mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-22 01:26:48 +03:00
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
This commit is contained in:
parent
aa10c7d918
commit
912e2d132f
|
@ -0,0 +1,3 @@
|
|||
export default function getSymbolObservable() {
|
||||
return (typeof Symbol === 'function' && Symbol.observable) || '@@observable';
|
||||
}
|
|
@ -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',
|
||||
|
@ -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>) {
|
||||
|
@ -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.');
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
declare global {
|
||||
interface SymbolConstructor {
|
||||
readonly observable: symbol;
|
||||
}
|
||||
}
|
||||
|
||||
const $$observable = /* #__PURE__ */ (() =>
|
||||
(typeof Symbol === 'function' && Symbol.observable) || '@@observable')();
|
||||
|
||||
export default $$observable;
|
Loading…
Reference in New Issue
Block a user