diff --git a/index.d.ts b/index.d.ts index b00c6f0885..a4c47b41ee 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,3 @@ -/// - /** * An *action* is a plain object that represents an intention to change the * state. Actions are the only way to get data into the store. Any data, @@ -224,6 +222,12 @@ export interface Unsubscribe { (): void } +declare global { + interface SymbolConstructor { + readonly observable: symbol; + } +} + /** * A minimal observable of state changes. * For more information, see the observable proposal: diff --git a/src/createStore.js b/src/createStore.js index 5326a52ff8..5e64e323d1 100644 --- a/src/createStore.js +++ b/src/createStore.js @@ -1,4 +1,4 @@ -import $$observable from 'symbol-observable' +import $$observable from './utils/symbol-observable' import ActionTypes from './utils/actionTypes' import isPlainObject from './utils/isPlainObject' diff --git a/src/utils/symbol-observable.js b/src/utils/symbol-observable.js new file mode 100644 index 0000000000..0fb198c986 --- /dev/null +++ b/src/utils/symbol-observable.js @@ -0,0 +1,3 @@ +// Inlined version of the `symbol-observable` polyfill +export default (() => + (typeof Symbol === 'function' && Symbol.observable) || '@@observable')() diff --git a/test/createStore.spec.js b/test/createStore.spec.js index dcbf65cf3e..a1f9cd9125 100644 --- a/test/createStore.spec.js +++ b/test/createStore.spec.js @@ -11,13 +11,16 @@ import { import * as reducers from './helpers/reducers' import { from } from 'rxjs' import { map } from 'rxjs/operators' -import $$observable from 'symbol-observable' +import $$observable from '../src/utils/symbol-observable' describe('createStore', () => { it('exposes the public API', () => { const store = createStore(combineReducers(reducers)) - const methods = Object.keys(store) + // Since switching to internal Symbol.observable impl, it will show up as a key in node env + // So we filter it out + const methods = Object.keys(store).filter(key => key !== $$observable) + expect(methods.length).toBe(4) expect(methods).toContain('subscribe') expect(methods).toContain('dispatch') diff --git a/test/typescript/store.ts b/test/typescript/store.ts index 685bfbf1b6..2d66396887 100644 --- a/test/typescript/store.ts +++ b/test/typescript/store.ts @@ -9,7 +9,8 @@ import { Unsubscribe, Observer, } from 'redux' -import 'symbol-observable' +// @ts-ignore +import $$observable from '../src/utils/symbol-observable' type BrandedString = string & { _brand: 'type' } const brandedString = 'a string' as BrandedString