Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Symbol.observable polyfill mismatch #1003

Merged
merged 5 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.