salsita / prism

React / Redux action composition made simple http://salsita.github.io/prism/
496 stars 24 forks source link

Issue with a specific unmounting situation #22

Closed namjul closed 8 years ago

namjul commented 8 years ago

I came across a situation where a component is not getting unmounted with the same actionPredix as it was mounted before. I build an example 'dynamic-tab-of-lists' where each list is an instance of 'dynamic-list-of-counters' The idea is to switch between them in a tabmenu. Now it works when you provide the key property with the index of the list, but this destroys and rebuilds the whole tree on each switch. Without the key the composition of dispatch in the forwardTo function changes (on tab-switch) and the components that gets unmounted wont have the right actionPrefix in their unmount action. It does not look like this can be solved with the current saga initialization process (mount/unmount) at least as far I could see.

https://github.com/namjul/redux-elm/tree/tabs-example/examples/dynamic-tab-of-lists/src/dynamic-tab-of-lists/view.js#L48

In verion 1.x.x this worked.

Preceding discussion on Gitter: https://gitter.im/salsita/redux-elm?at=574d97c180352f204df3c28e

tomkis commented 8 years ago

Unfortunately this is something we can't easily solve.

redux-elm (unlike) redux is about introducing Components where Component consists of View (which in fact is React Component - that's why Component in redux-elm is something different than component in React) and Updater.

To keep Sagas fractal we need to be able to determine when the Component has been mounted/unmounted which now is automatic process by abusing componentWillMount componentWillUnmount react lifecycle hooks.

The goal of redux-elm has never been to put the implementation burden on the user of the library. Therefore we have decided to couple Saga lifecycle with Component lifecycle.

tldr: automatic Sagas instantiation requires componentWIllMount

tomkis commented 8 years ago

Closing as it doesn't seem there's anything actionable.