UNPKG

mobx-create-stores

Version:

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

2 lines (1 loc) 1.66 kB
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("react-router"),require("mobx-react-router")):"function"==typeof define&&define.amd?define(["react-router","mobx-react-router"],r):t.mobxCreateStores=r(t.reactRouter,t.mobxReactRouter)}(this,function(t,r){"use strict";var o=function(r){var o=r.stores,e=void 0===o?[]:o,n=r.location,i=r.path,s=r.exact,u=void 0!==s&&s,c=r.strict,a=void 0!==c&&c,h=r.onMatch,d=t.matchPath(n.pathname,{path:i,exact:u,strict:a});d&&h&&h({stores:e,match:d,history:history})},e=function(t){var o=new r.RouterStore;return{history:r.syncHistoryWithStore(t,o),routerStore:o}},n=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.Store,o=t.history,e=void 0!==o&&o,n=new r;return e&&n.handleLocationChange&&e.subscribe(n.handleLocationChange),n},i=function(t){var r=t.constructor.name;return""+r.charAt(0).toLowerCase()+r.substring(1)},s=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.stores,o=t.history,s=void 0!==o&&o,u=void 0,c=void 0,a={};if(s){var h=e(s);c=h.history,u=h.routerStore}return r=r.map(function(t){return n({Store:t,history:c})}),s&&r.push(u),r.forEach(function(t){var r=i(t);a[r]=t,"production"!==process.env.NODE_ENV&&(window[r]=t)}),a};return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t.stores,e=void 0===r?[]:r,n=t.history,i=t.routes,u=void 0===i?[]:i,c=void 0;return e=s({history:n,stores:e}),e.routerStore&&u.length>0&&(c=e.routerStore.history,c.subscribe(function(t){u.forEach(function(r){return o(Object.assign({},r,{stores:e,location:t}))})})),{history:c,stores:e}}});