UNPKG

@sigi/devtool

Version:

Connect sigi to redux devtool

47 lines (43 loc) 1.29 kB
'use strict'; var core = require('@sigi/core'); var rxjs = require('rxjs'); let devtool = { send: rxjs.noop, init: rxjs.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); }; const initDevtool = () => { if (process.env.NODE_ENV === 'development') { devtool = ReduxDevTools.connect({ name: `Sigi`, }); devtool.init(STATE); core.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; } exports.initDevtool = initDevtool; //# sourceMappingURL=index.js.map