Skip to content

replaceMiddleware feature for use with lazy-loaded modules  #2041

@un33k

Description

@un33k

feature

It would be great to have a feature like replaceReducers() to replace the middlewares as well.
This is extremely handy where a lazy loaded module can register its middleware and the main app can add them to the existing middlewares and call replaceMiddlware() to activate them.

What is the current behavior?
The createStore() requires the middlewares upfront via applyMiddlware() in order to create the store. This makes the main app responsible for creating a list of middleware of all modules upfront.

What is the expected behavior?
It would be great to have the main app provide a registerMiddleware() function for modules to register their middlewares on load. The app can register the logger middleware itself, but each app will trigger its own middleware registration when loaded. In turn each call to registerMiddleware() will trigger a replaceMiddlware(). This way, splitting the code and lazy loading modules (Angular2) will work and load time of the first page will be much faster.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
macOS Sierra, Node v6.0.0, "redux": "^3.6.0", angular 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions