ReactiveX / ReactiveX/rxjs

Stop composing custom observable instances in version 8

Open
#5,431 3 comments 7 reactions 1 assignee View on GitHub

@benlesh is already working on this.

Since Aug 13, 2020.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

We are currently jumping through a lot of hoops in order to preserve the type through the operator chain, when that is no longer as relevant. As a hold-over from the dot-chained days, there was an attempt, starting in v5, to maintain the same type through operators by leveraging lift. This was done such that this would still work:

class CustomObservable<T> extends Observable<T> {
  specialMethod(): void { }
}

const custom = new CustomObservable<T>;

custom.filter(fn).map(fn2).mergeMap(fn3).specialMethod()

Over the years this has proven to have limited value, and in fact, is flawed in some ways. For example, look at the code we've had for years in order to support "lifting" publish operators in such a way that connect composes through.

Fact is, the current implementation doesn't support what it claims, because if you have more than one publish operator in the chain, it breaks connect. Try this:

This doesn't work:

interval(100).pipe(
  publish(),
  publish(),
  refCount()
).subscribe(x => console.log(x));

And this doesn't work:

const source = interval(100).pipe(publish(), publish());
source.subscribe(x => console.log(x));
source.connect();

This the byproduct of a few things, but chief among them are:

  1. publish() et al, should not be "pipeable operators".
  2. Composing custom types (or even Subject) through the operators via lift was a cool experiment, but ultimately was of limited value and required some strange workarounds in all cases.
  3. Implementing lift on a subclass of Observable requires the developer to have knowledge of Observable's implementation details. (You have to set subclass.operator and subclass.source etc).
For version 8, I'd like to eliminate the composition of types like ConnectableObservable, Subject and "custom observables" through operators as a goal.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.