ngrx / store

RxJS powered state management for Angular applications, inspired by Redux
MIT License
3.9k stars 310 forks source link

Redux encapsulation #76

Closed BaruchFisherman closed 8 years ago

BaruchFisherman commented 8 years ago

Dear all,

I'm writing a complicate app that 1) Have a reusable encapsulated components 2) our application is composed from different data flows which sometimes hold dependency between modules and slices of states for example: customer module, contains login component, when we want to preform login we should collect information from different states and component, for example, device meta data which is used in the login process should come from the device module..

therefore a few questions arise 1) what would be the correct and encapsulated way of creating such architecture? 2) Assuming that we have two different components; an Avatar from the customer module and a chat component from the chat module. these two are consistently showing on screen in parallel - both have their own private action creators and reducers which are responsible for the changes internally.by clicking on the user's avatar the chat should open. what would be the optimal way of creating decoupled components that allows this data flow (between the avatar and the chat module that may or may not be present) ?

I have read the following excellent article and I find the solution described there to be not fully encapsulated.

any ideas/comments/links/advice will be welcomed TIA

Rakatiri commented 8 years ago

Hi BaruchFisherman,

In the article you are referring to the comments from Sébastien Lorber were most useful to me. He proposes to accomplish true encapsulation by using sagas (see also: http://stackoverflow.com/questions/34570758/why-do-we-need-middleware-for-async-flow-in-redux/34623840#34623840 http://stackoverflow.com/questions/34570758/why-do-we-need-middleware-for-async-flow-in-redux/34623840#34623840).

He basically states that one could add an additional layer on top of the separate components that regulates such dependencies. For a saga imlementation for the ngrx/store see: https://github.com/CodeSequence/store-saga https://github.com/CodeSequence/store-saga

Op 22 mrt. 2016, om 14:54 heeft BaruchFisherman notifications@github.com het volgende geschreven:

Dear all,

I'm writing a complicate app that 1) Have a reusable encapsulated components 2) our application is composed from different data flows which sometimes hold dependency between modules and slices of states for example: customer module, contains login component, when we want to preform login we should collect information from different states and component, for example, device meta data which is used in the login process should come from the device module..

therefore a few questions arise 1) what would be the correct and encapsulated way of creating such architecture? 2) Assuming that we have two different components; an Avatar from the customer module and a chat component from the chat module. these two are consistently showing on screen in parallel - both have their own private action creators and reducers which are responsible for the changes internally.by clicking on the user's avatar the chat should open. what would be the optimal way of creating decoupled components that allows this data flow (between the avatar and the chat module that may or may not be present) ?

I have read the following excellent article http://blog.javascripting.com/2016/02/02/encapsulation-in-redux/ and I find the solution described there to be not fully encapsulated.

any ideas/comments/links/advice will be welcomed TIA

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/ngrx/store/issues/76

BaruchFisherman commented 8 years ago

@Rakatiri , I was readed this article and comments below. Redux-Saga is very good implementation, but how it resolve the problem that saga middileware's have to know about Event/Action names related to different moduls and action creators. Also this middlewar have to know different data types that only related to encapsulated modules?

Rakatiri commented 8 years ago

I don't see a problem there. Something has to know this stuff in order to bind the modules, right? I would put this in an higher order layer. N.B. I am also new to this stuff, so if anyone disagrees please let it know.

Op 23 mrt. 2016, om 14:02 heeft BaruchFisherman <notifications@github.com mailto:notifications@github.com> het volgende geschreven:

@Rakatiri https://github.com/Rakatiri , I was readed this article and comments below. Redux-Saga is very good implementation, but how it resolve the problem that saga middileware's have to know about Event/Action names related to different moduls and action creators. Also this middlewar have to know different data types that only related to encapsulated modules?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/ngrx/store/issues/76#issuecomment-200336829