redux-dynamic-modules icon indicating copy to clipboard operation
redux-dynamic-modules copied to clipboard

support for nested reducers

Open PhilippMelnikov opened this issue 5 years ago • 4 comments

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?

PhilippMelnikov avatar Oct 13 '20 10:10 PhilippMelnikov

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

dzintars avatar Oct 13 '20 10:10 dzintars

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

PhilippMelnikov avatar Oct 13 '20 11:10 PhilippMelnikov

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.

antokara avatar Nov 25 '20 00:11 antokara

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.

nkalinov avatar Jun 07 '22 14:06 nkalinov