microsoft / ReSub

A library for writing React components that automatically manage subscriptions to data sources simply by accessing them
MIT License
607 stars 49 forks source link

Discussion: Any examples on stores subscribing to other stores? #116

Closed thegalah closed 5 years ago

thegalah commented 5 years ago

In the readme under "Data Flows" it is mentioned that stores can subscribe to other stores. However my understanding of resub is that only ComponentBase components are able to subscribe to stores. Are there any examples on how this can be achieved?

deregtd commented 5 years ago

I'm actually not sure there are any examples. Just call store.subscribe(callbackFunc, keyIfAny) and it'll call your function back. Very simple pub-sub model for manual subscriptions to stores.

deregtd commented 5 years ago

(FWIW, I use this model all the time in my private projects -- stores subscribing to other stores and adding meta-value on top of the other store's more-raw data.) Just make sure that you unsubscribe if/when you're done with the data or the store will call you back forever. :)