@sigi/devtool
Version:
Connect sigi to redux devtool
41 lines • 1.24 kB
JavaScript
import { replaceLogger } from '@sigi/core';
import { noop } from 'rxjs';
let devtool = {
send: noop,
init: noop,
};
const FakeReduxDevTools = {
connect: () => devtool,
};
const ReduxDevTools = (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) ?? FakeReduxDevTools;
const STATE = {};
const logStateAction = (action) => {
const namespace = action.store.name;
const _action = {
type: `${namespace}/${action.type}`,
params: filterParams(action.payload),
};
STATE[namespace] = action.store.state;
devtool.send(_action, STATE);
};
export const initDevtool = () => {
if (process.env.NODE_ENV === 'development') {
devtool = ReduxDevTools.connect({
name: `Sigi`,
});
devtool.init(STATE);
replaceLogger(logStateAction);
}
};
function filterParams(params) {
if (params && typeof params === 'object' && typeof Event !== 'undefined') {
if (params instanceof Event) {
return `<<Event:${params.type}>>`;
}
else if (params.nativeEvent instanceof Event) {
return `<<SyntheticEvent:${params.nativeEvent.type}>>`;
}
}
return params;
}
//# sourceMappingURL=index.js.map