Skip to content
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

[Question] Extending Observable #1353

Closed
rolandjitsu opened this issue Feb 16, 2016 · 5 comments
Closed

[Question] Extending Observable #1353

rolandjitsu opened this issue Feb 16, 2016 · 5 comments

Comments

@rolandjitsu
Copy link

Do I need to add the lift() method if I only want to extend an Observable and not add an operator:

import {Observable} from 'rxjs/Observable';
class MyOwnObservable extends Observable {
    constructor() {
        super();
    }
    lift(operator) {
    const observable = new MyOwnObservable();
    observable.source = this;
    observable.operator = operator;
    return observable;
    }
}

Or is it enough to just extend the class:

import {Observable} from 'rxjs/Observable';
class MyOwnObservable extends Observable {
    constructor() {
        super();
    }
}
@trxcllnt
Copy link
Member

@rolandjitsu you only need to override lift if you want the Observable operators (such as map, filter etc.) to return instances of your Observable. This is generally most useful when you're extending to augment the Observable type, but it's also useful for other reasons, for example, to decorate Subscribers for logging or debugging. It's up to you.

@rolandjitsu
Copy link
Author

@trxcllnt thanks. It sounds like it is a good idea to have operators return instances of my own observable. Though not really sure if I actually need to extend the Observable. What I am after is:

let obs = new MyClass();
obs.subscribe(() => { ... });

And the class returned is not actually an array like object, it's more of a hash. Is it a good pattern or should I look at a different approach here?

@trxcllnt
Copy link
Member

@rolandjitsu I'm not totally clear on how you intend to use your class that extends Observable, but it's certainly not a problem that you do.

@rolandjitsu
Copy link
Author

That's alright. I think you already answered my question, so this can be closed. Thanks

Sent from my iPhone

On 16 Feb 2016, at 23:07, Paul Taylor [email protected] wrote:

@rolandjitsu I'm not totally clear on how you intend to use your class that extends Observable, but it's certainly not a problem that you do.


Reply to this email directly or view it on GitHub.

@lock
Copy link

lock bot commented Jun 7, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants