UNPKG

mobx-create-stores

Version:

creates an object with MobX stores (+ links stores to routes)

34 lines (21 loc) 586 B
import createRouterStore from './createRouterStore'; import createStore from './createStore'; import getStoreName from './getStoreName'; export default ({ stores: st, history: h = false, } = {}) => { let routerStore, history; const stores = {}; if (h) { ({history, routerStore} = createRouterStore(h)); } st = st.map(Store => createStore({Store, history})); if (h) st.push(routerStore); st.forEach(s => { const name = getStoreName(s); stores[name] = s; if (process.env.NODE_ENV !== `production`) window[name] = s; }); return stores; };