-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Subclassing Observable - Observable SubClasses extend Observable rather than MyObservable #1124
Comments
This is related with #642. Current modularity streategy does not correctly support extended definitions due to creation of observable (i.e, of, etcs..) always directly created |
MyObservable.of(42).customOperator() This wouldn't work on any type you subclassed in ES6. Imagine this simplified form: class A {
foo() {
console.log('foo from A');
}
static of() {
return new A();
}
}
class B extends A {
foo() {
console.log('foo from B');
}
}
var x = B.of();
console.log(x.foo()); // "foo from A" While |
On the |
@Nupf does the above information help you? |
While I was trying mixin approach in PR #643, I came to thought above scenario (maybe) possible in combination of enhanced typescript support (relates to #846). It was very vague idea at the moment and still not concrete clear due to known limitataions, reason bringing #642 is related. Even without direct static creator ( |
This is what Observable.of(42)
.let(o => MyObservable.from(o))
.customOperator()
.subscribe() |
Thanks for taking the time. @kwonoj: Thanks, I'll have a look at those. @Blesh: Yep, I was just hoping there was a way I didn't know about and/or I was just doing something wrong. @trxcllnt: Thanks, I didn't know about that operator. As far as I can tell, it's waiting to be merged in #1105, so I can't test it but it looks like it merely invokes the provided function on the source observable
As MyObservable.from returns the same thing Observable.from (@Blesh's comment) returns, this (as far as I can tell) won't convert o into an instance of MyObservable. As my original question is answered (not possible at the moment) I'll close this issue for now. |
@nupf ah, I was assuming |
@trxcllnt I thought about that but ran into problems with ConnectableObservable / publish. Is that how you would have implemented it?
It works great as long as the source observable only has a subscribe method (because that's what will be forwarded to myObservable.source on subscription to myObservable). ConnectableObservable destroys the illusion.
It works, but it doesn't feel clean. Thanks anyways :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I want to subclass Observable and extend it.
The documentation on this shows how to subclass observable and extend it with custom operators, however I run into problems whenever an operator / static method of MyObservable returns an instance of a different class.
All other Observable classes (e.g. ArrayObservable, ConnectableObservable) extend the original Observable class rather than MyObservable, meaning my custom operators will not be available.
How is subclassing meant to be used?
Overwriting the methods to wrap the returned Observable in an instance of MyObservable feels dirty.
The text was updated successfully, but these errors were encountered: