Branch: master
Find file Copy path
65640d3 Oct 3, 2018
2 contributors

Users who have contributed to this file

@keanulee @e111077
61 lines (50 sloc) 1.94 KB
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
The complete set of authors may be found at
The complete set of contributors may be found at
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at
import { ReducersMapObject, StoreEnhancer } from 'redux'
export interface LazyStore {
addReducers: (newReducers: ReducersMapObject) => void
A Redux store enhancer that lets you lazy-install reducers after the store
has booted up. Use this if your application lazy-loads routes that are connected
to a Redux store.
import { combineReducers } from 'redux';
import { lazyReducerEnhancer } from 'pwa-helpers/lazy-reducer-enhancer.js';
import someReducer from './reducers/someReducer.js';
export const store = createStore(
(state, action) => state,
Then, in your page/element, you can lazy load a specific reducer with:
export const lazyReducerEnhancer =
(combineReducers: typeof import('redux').combineReducers) => {
const enhancer: StoreEnhancer<LazyStore> = (nextCreator) => {
return (origReducer, preloadedState) => {
let lazyReducers = {};
const nextStore = nextCreator(origReducer, preloadedState);
return {
addReducers(newReducers) {
const combinedReducerMap: ReducersMapObject = {
this.replaceReducer(combineReducers(lazyReducers = combinedReducerMap));
return enhancer;