Skip to content

Commit

Permalink
Add support for Redux DevTools on RND
Browse files Browse the repository at this point in the history
  • Loading branch information
wnz99 committed Nov 1, 2020
1 parent 4f105f2 commit f0b1240
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions src/reduxDevtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ interface IORegisterInDevtoolsOptions {
}

export function registerInDevtools(stores: IPullstateAllStores, { namespace = "" }: IORegisterInDevtoolsOptions = {}) {
if (typeof document !== "undefined") {
const devToolsExtension = (window as any)?.__REDUX_DEVTOOLS_EXTENSION__;

if (devToolsExtension) {
for (const key of Object.keys(stores)) {
const store = stores[key];

const devToolsExtension = (window as any).__REDUX_DEVTOOLS_EXTENSION__;
if (devToolsExtension) {
const devTools = devToolsExtension.connect({ name: `${namespace}${key}` });
devTools.init(store.getRawState());
let ignoreNext = false;
/*store.subscribe(
const devTools = devToolsExtension.connect({ name: `${namespace}${key}` });
devTools.init(store.getRawState());
let ignoreNext = false;
/*store.subscribe(
(state) => {
if (ignoreNext) {
ignoreNext = false;
Expand All @@ -24,25 +24,24 @@ export function registerInDevtools(stores: IPullstateAllStores, { namespace = ""
},
() => {}
);*/
store.subscribe(
(s) => s,
(watched) => {
if (ignoreNext) {
ignoreNext = false;
return;
}
devTools.send("Change", watched);
store.subscribe(
(s) => s,
(watched) => {
if (ignoreNext) {
ignoreNext = false;
return;
}
);
devTools.send("Change", watched);
}
);

devTools.subscribe((message: { type: string; state: any }) => {
if (message.type === "DISPATCH" && message.state) {
ignoreNext = true;
const parsed = JSON.parse(message.state);
store.replace(parsed);
}
});
}
devTools.subscribe((message: { type: string; state: any }) => {
if (message.type === "DISPATCH" && message.state) {
ignoreNext = true;
const parsed = JSON.parse(message.state);
store.replace(parsed);
}
});
}
}
}

0 comments on commit f0b1240

Please sign in to comment.