.Net Knowledge Book : TypeScript, React, Redux, NodeJs by Patrick Desjardins

.Net Knowledge Book : TypeScript, React, Redux, NodeJs by Patrick Desjardins

Author:Patrick Desjardins [Desjardins, Patrick]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2017-12-18T22:00:00+00:00


The code is the enhancer that will be injected into the configuration. It was inspired by the Redux Batch Subscribe project. Some differences are that this is in TypeScript and that it is built to work with access to the store to make a decision about when to notify.

The following code shows how to set up the Redux’s enhancer. Normally, you’ll have many middlewares, some reducers, and when it’s time to set up your store you need to call for your enhancer. As you can see in the example below, we use the store to get a particular state we stored during the middleware phase to ensure we are in “batch mode”. When we are, we do not notify, we wait. Since changing the “batch mode” state will trigger a reducer to set the mode, we will come back in this function to notify.

const appliedMiddleware = applyMiddleware(

routesMiddleware,

...,

...,

normalizerMiddleware);

const reducersTyped = {

app: appReducer,

..., ...,

router: routerReducer

};

const reducers = combineReducers(reducersTyped);

const store: Store<AppReduxState> = createStore(

reducers,

composeEnhancers(

appliedMiddleware,

batchedSubscribeEnhancer((notify: () => void, storeSnapshot: Store<AppReduxState>) => {

if (!storeSnapshot.getState().app.isStoreInBatchMode) { notify();

}

})

));



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.