Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamically create new copies #102

Open
brennanerbz opened this issue Jan 22, 2016 · 4 comments
Open

dynamically create new copies #102

brennanerbz opened this issue Jan 22, 2016 · 4 comments

Comments

@brennanerbz
Copy link

Is there a way to dynamically add/create copies?

Using your universal example, if the user took an action to create a new counter-- how would a new copy of the counter reducer be created?

@adailey14
Copy link

@brennanerbz
I'm pretty sure multireducer does not support dynamic copies. I think you are better off writing your own reducer in that case and passing a key around that you can pass into your actions and use to access/manipulate many copies of your store data.

Look at how redux-form works for example - there is a single form reducer that creates many copies/instances of forms. I've used this pattern a lot and it works well. I've found that once you're comfortable writing reducers in that pattern there is little need for multireducer and it's almost always better to write one of these 'instance managing reducers' in case you need to support dynamic copies.

@erikras
Copy link
Owner

erikras commented Jan 23, 2016

Yeah, not really supported. Interesting idea, though.

@jephjohnson
Copy link

jephjohnson commented Mar 25, 2017

Any movement on this? Doesn't seem to work, if you're using your mulitreducer in an array but the length is constantly changing. I am fetching an api, so sometimes the results is 5, 10, 12, 15 and so on...Any thoughts on how to solve that? Not unless I say something along the lines of:

const thereducer = combineReducers({
  toggleCollection: multireducer({
    toggle0 : toggle,
    toggle1 : toggle,
    toggle2 : toggle,
    toggle3 : toggle,
    toggle4 : toggle,
    toggle5 : toggle,
    toggle6 : toggle,
    toggle7 : toggle,
    toggle8 : toggle,
    toggle9 : toggle,
    toggle10 : toggle
  }),

@einarq
Copy link

einarq commented Nov 28, 2017

@adailey14
Do you have an example like that you could point me to? I have the same need myself quite often, but haven't found a good example yet. Usually end up having a byId map in the reducer, and every action has the key and needs to do a deep update in the map. Not the most elegant solution...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants