gaearon / ama

Ask me anything!
222 stars 5 forks source link

Modifying a store/App State once its has been created. #94

Closed Aftabnack closed 8 years ago

Aftabnack commented 8 years ago

Hi Dan,

Big fan of your work, I don't think I'm fully able to understand and appreciate your effort considering I got introduced to Web Dev about 10 days ago.

So here is my question, From what I understand, you define reducers to mutate the state, and state contains everything that UI needs. Is there any possibility of adding a reducer(along with the state attribute it will be operating on) once its served on the Client Browser?

The use case being, adding a new component to the UI dynamically. The new component may need it's own data in the state tree, and consequently reducers to operate on them.

Am I even asking the right questions? Point me to specific resources for me to understand better.

Cheers!

gaearon commented 8 years ago

There is just one root reducer in the app. It calls other reducers as it sees fit, and it may indeed call some of them for dynamic keys. Here is an example: postsByReddit calls posts for a dynamic key defined in the action. It wasn’t there when the app started, but it is in the state now.

Hope it helps! For the future reference, this is my personal AMA, so it’s not the best place to ask technical questions about Redux. Please use StackOverflow for this instead.