Skip to content

RFC: Support from(Subscribable)Β #6490

@benlesh

Description

@benlesh

Idea

Support converting objects that have a subscribe() method to Observables.

class SomeThingy<T> {
   subscribe(observer: Observer<T>): { unsubscribe(): void } {
     /// stuff here.
    return {
       unsubscribe() {  }
    };
   }
}

const someThingy = new SomeThingy();

const anObservableOfSomeThingy$ = from(someThingy);

History

Originally, we opted not to do this, because RxJS 4 and under had observers that required methods that were different. Like { onNext, onError, onComplete }, where we had { next, error, complete }. Now that new usership of RxJS 4 and under is down, and mixed usership of RxJS 7 and RxJS 4 and under is almost non-existent, I think we can consider doing this.

Issues

  1. There are lots of APIs in the world that have a subscribe function. Many of them take just a single function instead of an observer object. Can we support that too? or only Observer arguments?
  2. We may at some point move to using AbortSignal as the second argument to subscribe, do we want to account for that now? We'd at least have to leave room.
  3. Do we support returns of void or only if they return an Unsubscribable?
  4. Should it just be a "from" helper? fromSubscribable?

Other things

This isn't a "for sure" plan. Thus far we haven't had much need or many requests for this feature. I just think it's time to consider it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions