Stop composing custom observable instances in version 8
@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:
publish()et al, should not be "pipeable operators".- Composing custom types (or even Subject) through the operators via
liftwas a cool experiment, but ultimately was of limited value and required some strange workarounds in all cases. - Implementing
lifton a subclass ofObservablerequires the developer to have knowledge ofObservable's implementation details. (You have to setsubclass.operatorandsubclass.sourceetc).
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.