-
Notifications
You must be signed in to change notification settings - Fork 90
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
Symbol.observer? #89
Comments
Dumb question: why do we need a special symbol for this? Won't any object with next/error/complete "just work" in place of an observer? |
I agree with @benjamingr, Promises have a concept of Edit: Though Promises/A+ didn't really have Symbols to consider when they were defining the spec, so I'm not sure it's relevant. |
@RangerMauve it would have been easy and still is to add a Symbol for promises resolving (although amusingly nominally typed languages like C#'s use a structural interface GetAwaiter :P). Work has been done on promises since (async/await) and there didn't seem to be an urgent need for this. That said - I'm not saying we shouldn't have a Symbol here - just that I do not understand its purpose. |
I see your argument, couldn't anyone just create a POJO with Let's say console had some hypothetical console[Symbol.observer] = function symbolObserver() {
return {
next: (value) => this.log(value),
error: (err) => this.error(value),
complete: () => this.info('complete', value),
}
}; Then you could log out all observable emissions like so: someObservable.subscribe(console); Probably the same reason any object with a
|
So a "nextable"? You could just be detecting an iterator, though. |
It's a cool idea, and one that I hadn't considered. I'm comfortable leaving it aside for now, though, until we get through the changes to |
any updates on this? |
I've just been subclassing Observable to also quack like an Observer. If only that were possible in RxJS, but I believe that possibility is being considered now there, too. |
@isiahmeadows... In RxJS you're looking for subjects. You can even "glue" an observer to an observable with |
@Blesh I'm aware of RxJS's Subjects, it's just that I'm limited to |
It's pretty straightforward to do, though. |
As far as I know RxJS 4 does, and RxJS 5 definitely does support subclassing Observable. You should file a ticket on https://github.com/reactivex/rxjs if you're having an issue subclassing, or there's a particular features you're requesting. |
@isiahmeadows 🙂 I wrote a majority of RxJS 5. While there are minor ergonomics gaps in subclassing Observables (which is what we're discussing in that issue), they are very minor. We subclass Observable throughout the library, and it's something that we've done in redux-observable and others have done Angular 2 related libraries. Either way, this is all off-topic. 🙂 But you should feel free to subclass RxJS 5 Observables. |
@Blesh Okay. I'll take your word for it, then. |
I think that
Symbol.observable
is a fine interop point. I was going through to add Observable interoperability to a project that isn't rx-related, and I noticed something: While sometimes I wanted to be able to subscribe to another object with[Symbol.observable]()
, other times I wanted to use the other object as an observer.Would it be worth considering a
Symbol.observer
? That is, a symbol that can be used to identify an object as an observer. Could be useful for generators as well as custom objects.(lol... "Observerable", I'm kidding there, of course).
The text was updated successfully, but these errors were encountered: