UNPKG

mobx-create-stores

Version:

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

31 lines (24 loc) 862 B
import linkHandlers from './lib/linkHandlers'; import createStoresObj from './lib/createStoresObj'; export default (function () { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$stores = _ref.stores, stores = _ref$stores === undefined ? [] : _ref$stores, h = _ref.history, _ref$routes = _ref.routes, routes = _ref$routes === undefined ? [] : _ref$routes; var history = void 0; stores = createStoresObj({ history: h, stores: stores }); if (stores.routerStore && routes.length > 0) { history = stores.routerStore.history; history.subscribe(function (location) { routes.forEach(function (r) { return linkHandlers(Object.assign({}, r, { stores: stores, location: location })); }); }); } return { history: history, stores: stores }; });