jspuij / Cortex.Net

State management like MobX for .NET and Blazor
https://jspuij.github.io/Cortex.Net.Docs
MIT License
81 stars 11 forks source link

Subscribing observables to other observables #48

Open WhitWaldo opened 3 years ago

WhitWaldo commented 3 years ago

I'd like to have observables be able to subscribe directly to other observables so they might update their own values reactively.

Today, I can solve this imperatively. If I have a ParentStore and a ChildStore, I can inject the latter into the former. Within ParentStore, when an action method is called to update a value imperatively, I can point to my ChildStore reference and imperatively call an action on it in order to effect some changed value on it.

The downside to doing it this way is that my DI registration winds up having to be far too knowledgeable about what stores are intending to be subscribed to what as I fill the constructor of each store with injected instances of each other dependent store. Further, it's suddenly not reactive so much as imperative, leaving the only reactive component being the state rendered in Blazor.

What am I missing that would allow observables to subscribe to values on other observables and in turn be able to change their own values? Thank you!

jspuij commented 3 years ago

@WhitWaldo I'm not sure I'm following you without a small sample, but the most obvious way would be to build a tree from your observable state and attach everything to the same shared state. There is no concept of a store in Cortex.Net, there is just observable state, with reactions tied to them.