Skip to content

Commit 0d7d94d

Browse files
committed
Inline the symbol-observable polyfill
1 parent b882d9a commit 0d7d94d

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

index.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="symbol-observable" />
2-
31
/**
42
* An *action* is a plain object that represents an intention to change the
53
* state. Actions are the only way to get data into the store. Any data,
@@ -224,6 +222,12 @@ export interface Unsubscribe {
224222
(): void
225223
}
226224

225+
declare global {
226+
interface SymbolConstructor {
227+
readonly observable: symbol;
228+
}
229+
}
230+
227231
/**
228232
* A minimal observable of state changes.
229233
* For more information, see the observable proposal:

src/createStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import $$observable from 'symbol-observable'
1+
import $$observable from './utils/symbol-observable'
22

33
import ActionTypes from './utils/actionTypes'
44
import isPlainObject from './utils/isPlainObject'

src/utils/symbol-observable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Inlined version of the `symbol-observable` polyfill
2+
export default (() =>
3+
(typeof Symbol === 'function' && Symbol.observable) || '@@observable')()

test/createStore.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import {
1111
import * as reducers from './helpers/reducers'
1212
import { from } from 'rxjs'
1313
import { map } from 'rxjs/operators'
14-
import $$observable from 'symbol-observable'
14+
import $$observable from '../src/utils/symbol-observable'
1515

1616
describe('createStore', () => {
1717
it('exposes the public API', () => {
1818
const store = createStore(combineReducers(reducers))
19-
const methods = Object.keys(store)
2019

20+
// Since switching to internal Symbol.observable impl, it will show up as a key in node env
21+
// So we filter it out
22+
const methods = Object.keys(store).filter(key => key !== $$observable)
23+
2124
expect(methods.length).toBe(4)
2225
expect(methods).toContain('subscribe')
2326
expect(methods).toContain('dispatch')

test/typescript/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Unsubscribe,
1010
Observer,
1111
} from 'redux'
12-
import 'symbol-observable'
12+
// @ts-ignore
13+
import $$observable from '../src/utils/symbol-observable'
1314

1415
type BrandedString = string & { _brand: 'type' }
1516
const brandedString = 'a string' as BrandedString

0 commit comments

Comments
 (0)