Skip to content

Commit

Permalink
Fix Symbol.observable polyfill mismatch (#1003)
Browse files Browse the repository at this point in the history
* Remove spreading store in instrument

* Add subscribe method

* Ignore ESLint error

* Resolve Symbol.observable at store creation time

* Add warning
  • Loading branch information
Methuselah96 committed Jan 12, 2022
1 parent aa10c7d commit 912e2d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
3 changes: 3 additions & 0 deletions packages/redux-devtools-instrument/src/getSymbolObservable.ts
@@ -0,0 +1,3 @@
export default function getSymbolObservable() {
return (typeof Symbol === 'function' && Symbol.observable) || '@@observable';
}
21 changes: 14 additions & 7 deletions packages/redux-devtools-instrument/src/instrument.ts
@@ -1,16 +1,16 @@
import difference from 'lodash/difference';
import union from 'lodash/union';
import isPlainObject from 'lodash/isPlainObject';
import $$observable from './symbol-observable';
import {
Action,
Observable,
Observer,
PreloadedState,
Reducer,
Store,
StoreEnhancer,
StoreEnhancerStoreCreator,
} from 'redux';
import getSymbolObservable from './getSymbolObservable';

export const ActionTypes = {
PERFORM_ACTION: 'PERFORM_ACTION',
Expand Down Expand Up @@ -903,13 +903,21 @@ export function unliftStore<
return action;
}

return {
...liftedStore,
const $$observable = getSymbolObservable();
if (!($$observable in liftedStore)) {
console.warn(
'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.'
);
}

return {
liftedStore,

dispatch,

// eslint-disable-next-line @typescript-eslint/unbound-method
subscribe: liftedStore.subscribe,

getState,

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

[$$observable](): Observable<S> {
[$$observable]() {
return {
...(liftedStore as any)[$$observable](),
subscribe(observer) {
subscribe(observer: Observer<S>) {
if (typeof observer !== 'object') {
throw new TypeError('Expected the observer to be an object.');
}
Expand Down
10 changes: 0 additions & 10 deletions packages/redux-devtools-instrument/src/symbol-observable.ts

This file was deleted.

0 comments on commit 912e2d1

Please sign in to comment.