ioof-holdings / redux-dynostore

These libraries provide tools for building dynamic Redux stores.
BSD 3-Clause "New" or "Revised" License
122 stars 15 forks source link

How to use nested dynamic functions calls without nesting substores? #243

Closed macklay closed 4 years ago

macklay commented 4 years ago
const mountFirstModule = dynamic('module1', subspaced(), attachReducer(myReducer), runSaga(mySaga))
const mountSecondModule = dynamic('module2', subspaced(), attachReducer(myReducer), runSaga(mySaga))

export default mountFirstModule(mountSecondModule(MyComponent))

Now I get such store structure: store: { module1: { module2: {...} } } but I need something like this: store: { module1: {...} module2: {...} }

mpeyper commented 4 years ago

You're going to have to give me more context around the problem you're trying to solve here as the structure you're looking for is not intuitive to the underlying component structure so MyComponent won't be able to resolve the state for one of the modules if you do that.

Unless you want MyComponent's view of the store to include both module keys as well, in which case you probably don't want 2 layers of dynamic involved.

Finally, removing subspaced and using the non-subspace version of attachReducer and runSaga should give you that structure (i.e. all dynamic things end up in the root), but you will need to handle the state resolution in your component yourself (i.e. they will not be subspaced and the connect will receive the root state).

macklay commented 4 years ago

I think, I found solution. If I pass context in subspace in this way it works:

dynamic(
          moduleName,
          subspaced({ subspaceOptions: { context: { parent: context } } }),
          attachReducer(reducer),
          runSaga(saga),
          { context },
        ),

Unfortunately current dynostore version is not support subspaceOptions parameter. I tried to make pull request with this ability(https://github.com/ioof-holdings/redux-dynostore/pull/237) but now I dont have free time to make it in more appropriate way.

mpeyper commented 4 years ago

237 has been released in v3.1.0. Please try it out and let me know how you go. I'll close this for now, but if you have issues we'll reopen it and work through it.