UNPKG

2.71 kBSource Map (JSON)View Raw
1{"version":3,"file":"lazy-reducer-enhancer.js","sourceRoot":"","sources":["src/lazy-reducer-enhancer.ts"],"names":[],"mappings":"AAAA;;;;;;;;EAQE;AAQF;;;;;;;;;;;;;;;;;;;;;EAqBE;AACF,MAAM,CAAC,MAAM,mBAAmB,GAC9B,CAAC,eAAuD,EAAE,EAAE;IAC1D,MAAM,QAAQ,GAA6B,CAAC,WAAW,EAAE,EAAE;QACzD,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,EAAE;YACrC,IAAI,YAAY,GAAG,EAAE,CAAC;YACtB,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YAC3D,yBACK,SAAS,IACZ,WAAW,CAAC,WAAW;oBACrB,MAAM,kBAAkB,qBACnB,YAAY,EACZ,WAAW,CACf,CAAC;oBAEF,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,YAAY,GAAG,kBAAkB,CAAC,CAAC,CAAC;gBAC1E,CAAC,IACF;QACH,CAAC,CAAA;IACH,CAAC,CAAA;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["/**\n@license\nCopyright (c) 2018 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\nimport { ReducersMapObject, StoreEnhancer } from 'redux'\n\nexport interface LazyStore {\n addReducers: (newReducers: ReducersMapObject) => void\n}\n\n/**\n A Redux store enhancer that lets you lazy-install reducers after the store\n has booted up. Use this if your application lazy-loads routes that are connected\n to a Redux store.\n\n Example:\n\n import { combineReducers } from 'redux';\n import { lazyReducerEnhancer } from 'pwa-helpers/lazy-reducer-enhancer.js';\n import someReducer from './reducers/someReducer.js';\n\n export const store = createStore(\n (state, action) => state,\n compose(lazyReducerEnhancer(combineReducers))\n );\n\n Then, in your page/element, you can lazy load a specific reducer with:\n\n store.addReducers({\n someReducer\n });\n*/\nexport const lazyReducerEnhancer =\n (combineReducers: typeof import('redux').combineReducers) => {\n const enhancer: StoreEnhancer<LazyStore> = (nextCreator) => {\n return (origReducer, preloadedState) => {\n let lazyReducers = {};\n const nextStore = nextCreator(origReducer, preloadedState);\n return {\n ...nextStore,\n addReducers(newReducers) {\n const combinedReducerMap: ReducersMapObject = {\n ...lazyReducers,\n ...newReducers\n };\n\n this.replaceReducer(combineReducers(lazyReducers = combinedReducerMap));\n }\n }\n }\n }\n\n return enhancer;\n };\n"]}
\No newline at end of file