UNPKG

nedux-logger

Version:

the next redux state management

41 lines (33 loc) 1.16 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory(global['nedux-logger'] = {})); }(this, (function (exports) { 'use strict'; const GLOBAL_STATE = {}; const DEVTOOL_INSTANCE = window && // @ts-ignore window.__REDUX_DEVTOOLS_EXTENSION__ && // @ts-ignore window.__REDUX_DEVTOOLS_EXTENSION__.connect({ instanceId: '@nedux' }); const logger = storeName => store => { if (!DEVTOOL_INSTANCE) { return; } const FORMATTED_STORE_NAME = storeName.toUpperCase(); GLOBAL_STATE[storeName] = {}; store.subscribe('', (value, key) => { const type = key in GLOBAL_STATE[storeName] ? `[${FORMATTED_STORE_NAME}] UPDATE ${key}` : `[${FORMATTED_STORE_NAME}] INIT ${key}`; DEVTOOL_INSTANCE.send({ type, payload: value }, GLOBAL_STATE); GLOBAL_STATE[storeName] = { ...GLOBAL_STATE[storeName], [key]: value }; }, { withInitialValue: true }); }; exports.logger = logger; Object.defineProperty(exports, '__esModule', { value: true }); })));