Clarification in readme's "Making an object observable"
darcyparker opened this issue · comments
See https://github.com/benlesh/symbol-observable#making-an-object-observable
- The guidance is good, but it should probably handle the 2 forms of
subscribe()
, otherwise it won't satisfy the variousObservableLike
type definitions in the wild. (2 forms here: https://github.com/tc39/proposal-observable#observable) The form with callback args rather than the object with callback args is popular in manyObservableLike
implementations.
Also, I thought your recent blog https://benlesh.com/posts/learning-observable-by-building-observable/ was very helpful. It may be worth adding it as a reference.
The only form that was ever meant to be handled was basically this:
interface Unsubscribable {
unsubscribe(): void;
}
interface Observer<T> {
next(value: T): void;
error(err: any): void;
complete();
}
interface ObservableLike<T> {
subscribe(): Unsubscribable;
subscribe(observer: Partial<Observer<T>>): Unsubscribable;
}
interface ObservableInterop<T> {
[Symbol.observable](): ObservableLike<T>;
}