KarlPurk/redux-decorators

Subscribe Support?

Closed this issue · 2 comments

Is there a was to subscribe to appState's state changes? The simple bindings for component properties is phenomenal, but my components and services need to run custom code on state change.
My proposed enhancement is for @Store to detect which stateProperties are functions and have them subscribe to appStore.

I wanted to check that there wasn't an easier existing method to subscribe to @Store and that the above proposed implementation was acceptable before I started working on an enhancement in my fork.

Thanks!

This can currently be achieved by accessing the injected appStore property in any class that uses the @Store() decorator - this is not yet documented in the readme.

Another alternative, although not currently implemented, is to piggy back on the existing handler. Currently the @Store() decorator adds a handleStoreUpdate method to each class it decorates. This handles updating properties on the decorated class. It would be simple to allow users to declare this method themselves, while preserving existing functionality. We already do this with ngOnInit and ngOnDestroy.

I'm not against to extending the API to support this, but I feel it's a little too soon to implement this right now. I'd like to see if this is a common use-case before supporting it in the core API.

Cheers!

I think this is resolved. I believe the appStore property satisfies the requirement? I want to investigate implementing observables for the store-connected properties. This will give you the option of subscribing to individual slice changes in addition to using the appStore properties to observe all state changes.