Home

Awesome

<div> <img src="docs/redux-dynamic-modules.png" alt="logo" width="100"> </img> <h1>Redux Dynamic Modules</h1< </div>

Pipelines npm (scoped) Join the chat at https://gitter.im/redux-dynamic-modules/community GitHub license

What is it?

redux-dynamic-modules is a library that aims to make Redux Reducers and middleware easy to modular-ize and add/remove dynamically.

Motivation

In large Javascript applications, it is often desired to perform some kind of code-splitting, so that the initial script size is small. However, in Redux, you are required to define your reducers and middleware up-front; there is no good way to dynamically add/remove these constructs at runtime.

redux-dynamic-modules is designed to make dynamically loading these constructs easier. You can define a module, which contains reducers and middleware, and add it to the Redux store at runtime. We also provide a React component DynamicModuleLoader, which can load/unload modules on mount/unmount.

Modules provide the following benefits:

Features

Example Scenarios

Install

Run

npm install redux-dynamic-modules

or

yarn add redux-dynamic-modules

Usage

export function getUsersModule(): IModule<IUserState> {
    return {
        id: "users",
        reducerMap: {
            users: usersReducer,
        },
        // Actions to fire when this module is added/removed
        // initialActions: [],
        // finalActions: []
    };
}
import { createStore, IModuleStore } from "redux-dynamic-modules";
import { getUsersModule } from "./usersModule";

const store: IModuleStore<IState> = createStore({
      initialState: { /** initial state */ },
      enhancers: [ /** enhancers to include */ ], 
      extensions: [/** extensions to include i.e. getSagaExtension(), getThunkExtension() */],
},
    getUsersModule()
    /* ...any additional modules */
);
<DynamicModuleLoader modules={[getHelloWorldModule()]}>
    <div>Hello World!!</div>
</DynamicModuleLoader>

Extensions

Examples

See the Widgets for a quick of example of the library in practice.

Step by step walthrough of start consuming redux-dynamic-modules in the widget app. Youtube

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.