microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 116 forks source link

support for nested reducers #160

Open PhilippMelnikov opened 3 years ago

PhilippMelnikov commented 3 years ago

Hello! Does the library provide support for loading nested reducers? Suppose i have a store structure like this { auth, me: { counters, orders } }

I want to load reducers for orders later. How do I do that?

dzintars commented 3 years ago

Mby this - https://redux-dynamic-modules.js.org/#/reference/Dependencies ?

PhilippMelnikov commented 3 years ago

If we take example from docs you're suggesting, what would the final structure of the store look like?

antokara commented 3 years ago
import { combineReducers} from '@reduxjs/toolkit';

interface ICountersState {
  counters: number;
};

interface IOrdersState {
  orders: number;
};

interface IMeState {
  me: {
    counters: ICountersState;
    orders: IOrdersState;
  }
};

const counters = (state, action) => { // your reducer for counters };
const orders = (state, action) => { // your reducer for orders };

const meModule: IModule<IMeState> = {
  id: 'me',
  reducerMap: {
    me: combineReducers({ counters, orders })
  }
};

@PhilippMelnikov give it a try and let me know. I think this should be added to the documentation because it is a very common use case.

nkalinov commented 2 years ago

I just added support for this via lodash.set paths in this PR: https://github.com/microsoft/redux-dynamic-modules/pull/195 Looking at this repo's activity I do not expect it to be merged (soon) so if you want you can use it immediately with npm gh link: "redux-dynamic-modules": "https://github.com/nkalinov/redux-dynamic-modules.git" That's what I'm going to do at least.