Skip to content

Commit 912e2d1

Browse files
authored
Fix Symbol.observable polyfill mismatch (#1003)
* Remove spreading store in instrument * Add subscribe method * Ignore ESLint error * Resolve Symbol.observable at store creation time * Add warning
1 parent aa10c7d commit 912e2d1

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function getSymbolObservable() {
2+
return (typeof Symbol === 'function' && Symbol.observable) || '@@observable';
3+
}

packages/redux-devtools-instrument/src/instrument.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import difference from 'lodash/difference';
22
import union from 'lodash/union';
33
import isPlainObject from 'lodash/isPlainObject';
4-
import $$observable from './symbol-observable';
54
import {
65
Action,
7-
Observable,
6+
Observer,
87
PreloadedState,
98
Reducer,
109
Store,
1110
StoreEnhancer,
1211
StoreEnhancerStoreCreator,
1312
} from 'redux';
13+
import getSymbolObservable from './getSymbolObservable';
1414

1515
export const ActionTypes = {
1616
PERFORM_ACTION: 'PERFORM_ACTION',
@@ -903,13 +903,21 @@ export function unliftStore<
903903
return action;
904904
}
905905

906-
return {
907-
...liftedStore,
906+
const $$observable = getSymbolObservable();
907+
if (!($$observable in liftedStore)) {
908+
console.warn(
909+
'Symbol.observable as defined by Redux and Redux DevTools do not match. This could cause your app to behave differently if the DevTools are not loaded. Consider polyfilling Symbol.observable before Redux is imported or avoid polyfilling Symbol.observable altogether.'
910+
);
911+
}
908912

913+
return {
909914
liftedStore,
910915

911916
dispatch,
912917

918+
// eslint-disable-next-line @typescript-eslint/unbound-method
919+
subscribe: liftedStore.subscribe,
920+
913921
getState,
914922

915923
replaceReducer(nextReducer: Reducer<S & NextStateExt, A>) {
@@ -923,10 +931,9 @@ export function unliftStore<
923931
);
924932
},
925933

926-
[$$observable](): Observable<S> {
934+
[$$observable]() {
927935
return {
928-
...(liftedStore as any)[$$observable](),
929-
subscribe(observer) {
936+
subscribe(observer: Observer<S>) {
930937
if (typeof observer !== 'object') {
931938
throw new TypeError('Expected the observer to be an object.');
932939
}

packages/redux-devtools-instrument/src/symbol-observable.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)