-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObserveState extension #57
Conversation
@GuillaumeSalles I have been researching observables all day partly for use within redux extensions and partly for a project I am working on, but I am not that familiar with them yet. It looks like a very simple extension that attaches to the state changed event, however I am still questioning the validity of the state changed event vs just subscribing. If the event wasn't part of the store would this still be possible? |
When you say : " event vs just subscribing", are you referring to C# event vs Observable or C# event vs Subscribe method like in redux.js ? I'm not sure to understand this :
|
Yeah what I meant was - If the store was implemented as redux.js, eg
could the observable extension still work? And If so, could we implement the store as redux.js and have both an event-based extension and a observable based extension so that store was as low level as redux.js |
If the store was created exactly like redux.js, the observable could be build as an extension method (with Observable.Create instead of Observable.FromEvent), but the Event couldn't be built as an extension method. It would be possible as an adapter (Adapter pattern). IMHO, C# event are as low level as redux.js subscribe method. StateChanged event and subscribe have exactly the same external properties. C# event are just more pratical because internally, you don't have to keep a list of subscribers. I'm confident that redux.js creators would have use a language construct like C# events if they had exist in javascript. |
So if I understand correctly, one can get state updates by:
Why have you called the Another note: I think we should consider implementing support for a kind of store only surfacing the state through @dcolthorp, wanna take a look at this PR? |
@lilasquared, @cmeeren : wow, I'm so confused. I don't know how could I have misread your comments for so long. I worked with redux.js for 2 years and the idea that subscribe listener takes the state as parameter was so deeply integrated in my mind that my brain somewhat obfuscated your arguments. My mistake. Thanks a lot to have insisted on this point. I will make another PR after this one to implement it without parameter (to finally be as orthogonal as the js version :)). Or maybe one of you want to take a try?
Yeah.
My goal with v3 will be to enable opinionated extensions ,like your ProjectingStore or the @dcolthorp 's one, to be built on top of redux. With this architecture, you will still be able to use other open source Middlewares or the devtools for free. I'll try to make a PR soon to handle your extensions. |
Sure, sounds fine. We'll just have to make sure that the extensions are (as far as possible) orthogonal and compatible. :) I've lost track of the exact number of extensions we've talked about and their specifics. |
The PR was a little bit heavier than expected so I did it. Sorry if one of you worked on it... See #58
Just a bad refactoring after the Rx version. Fixed in #58 |
I propose the solution 2 explained in this comment
I think it's the cleaner approach.
@cmeeren, you quoted this earlier :
I agree but for the solution 1, you don't have other choice if you want to have other method on your custom observable.
Also, Observable.FromEvent is okay for our use case (link)
(I read this website in 2011 and it's still the best Rx reference 👌 )
What do you think ?