diff --git a/src/spy.js b/src/spy.js index 8c495ee..3c021d1 100644 --- a/src/spy.js +++ b/src/spy.js @@ -5,6 +5,7 @@ import { isFiltered } from './filters'; import { dispatchMonitorAction } from './monitorActions'; let isSpyEnabled = false; +let fallbackStoreName; const stores = {}; const onlyActions = {}; const filters = {}; @@ -15,6 +16,10 @@ function configure(name, config = {}) { if (typeof config.onlyActions === 'undefined') onlyActions[name] = mobx.useStrict(); else onlyActions[name] = config.onlyActions; if (config.filters) filters[name] = config.filters; + if (config.global) { + if (fallbackStoreName) throw Error("You've already defined a global store"); + fallbackStoreName = name; + } } function init(store, config) { @@ -56,10 +61,15 @@ export default function spy(store, config) { schedule(objName); return; } + if (!stores[objName]) objName = fallbackStoreName; if (!stores[objName] || stores[objName].__isRemotedevAction) { schedule(objName); return; } + if (change.fn && change.fn.__isRemotedevAction) { + schedule(objName); + return; + } if (change.type === 'action') { const action = createAction(change.name); if (change.arguments && change.arguments.length) action.arguments = change.arguments; diff --git a/src/utils.js b/src/utils.js index 1e38d08..bfb37ce 100644 --- a/src/utils.js +++ b/src/utils.js @@ -42,7 +42,7 @@ export const silently = (fn, store) => { delete store.__isRemotedevAction; }; -export const setValue = mobx.action('@@remotedev', (store, state) => { +function setValueAction(store, state) { silently(() => { if (store.importState) { store.importState(state); @@ -53,5 +53,7 @@ export const setValue = mobx.action('@@remotedev', (store, state) => { } }, store); return state; -}); +} +setValueAction.__isRemotedevAction = true; +export const setValue = mobx.action('@@remotedev', setValueAction); /* eslint-enable */