mobx-create-stores
Version:
creates an object with MobX stores (+ links stores to routes)
36 lines (24 loc) • 547 B
JavaScript
import linkHandlers from './lib/linkHandlers';
import createStoresObj from './lib/createStoresObj';
export default ({
stores = [],
history: h,
routes = []
} = {}) => {
let history;
stores = createStoresObj({
history: h,
stores
});
if (stores.routerStore && routes.length > 0) {
({history} = stores.routerStore);
history.subscribe(location => {
routes.forEach(r => linkHandlers(
Object.assign(
{}, r, {stores, location})
)
);
});
}
return {history, stores};
};