-
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/extending Observable - is it currently feasible? #1757
Comments
@halhenke yes, it's a viable solution. In fact our docs outline it as a way to add operators to a custom observable: https://github.com/ReactiveX/rxjs/blob/master/doc/operator-creation.md#adding-the-operator-to-observable |
I hope you find that helpful. I'm closing for now, as I think I've answered your question. |
Thanks for responding @Blesh the problem seems to be that some operators will use the custom e.g. the map operators uses export function map<T, R>(project: (value: T, index: number) => R, thisArg?: any): Observable<R> {
//...
return this.lift(new MapOperator(project, thisArg));
} https://github.com/ReactiveX/rxjs/blob/master/src/operator/map.ts#L42 while the export function concatStatic<T, R>(...observables: Array<ObservableInput<any> | Scheduler>): Observable<R> {
// ...
return new ArrayObservable(observables, scheduler).lift(new MergeAllOperator<R>(1));
} https://github.com/ReactiveX/rxjs/blob/master/src/operator/concat.ts#L122 I may be missing something (I hope so) but it would seem that this means its not currently possible to extend Observables in a consistent way (always getting back the Custom Observable) without rewriting/overriding lots of stuff. |
Have the same issue, import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { map } from 'rxjs/operator/map';
class ObservableExt extends Observable {
static of= (...args) => new ObservableExt(subs => of(...args).subscribe(subs));
lift(operator) {
const observable = new ObservableExt();
observable.source = this;
observable.operator = operator;
return observable;
}
map=map;
}
export default ObservableExt; And looks like for each creation operator we should do the trick like for |
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. |
Hey,
Apologies for making this an issue - dont mean to abuse the system - but had asked on Gitter etc and not gotten a response.
I just wanted to get an idea if creating a subclass and overriding lift was a viable approach at this point in order to get a Custom Observable that will always return the same Custom Observable.
From trying to follow this approach though it seems that operators like
merge
,concat
etc callArrayObservable.lift
and not the overriddenlift
method and thus return an ordinary observable.Basically what I was interested in was creating an Observable that kept a reference to some Immutable state and would pass it along to the next Observer if that helps at all.
re:
#60
#1124
The text was updated successfully, but these errors were encountered: