- Seems like it's okay. There's
PartialObserver<T>andObserver<T>as the main exports.
Subscriptionis currently a class implementation.ISubscriptionis closest to the spec, andAnonymousSubscriptionis any object returning anunsubscribe()method.ISubscriptionshould be renamed toSubscription. This means the currentSubscriptionclass (which is used almost exclusively in type position) would be renamed toRxSubscription. See description below inObservablefor howRxSubscriptionandSubscriptionwould be implemented and used.
- Per the comments in this file, this class is rarely used outside RxJS. It extends
Subscription(discussed above) and implementsObserver. In the Observable spec, this type is calledSubscriberFunctionand the public API is close, but the Rx implementation adds theunsubscribe()method. - We should probably define the
SubscriberFunctiontype and use it wherever possible. Should be discussed with Ben to find out if this type should haveunsubscribe()by default. - Maybe we should split this out so it's not a subclass of
Subscription. This would mean.subscribewould return a real subscription rather than just being cast to Subscription.
(OuterSubscriber](https://github.com/ReactiveX/rxjs/blob/master/src/internal/OuterSubscriber.ts) & InnerSubscriber:
- I don't think we need to make changes here. These types are used internally within operators and are not part of the public API.
- Part of
Observable.tsdefining thesubscribe()method. Should be updated to return the newSubscriptionas currently it returnsAnonymousSubscription.
- Move current
ObservabletoRxObservable. Create new, minimalisticObservableinterface. Make sure both are compatible.- Requires making
RxObservableproperties/methods optional. Probably should re-work how this is defined to be quicker and create fewer hidden classes. Will be something like this:
- Requires making
export interface Observable<T> {
constructor(subscribe?: SubscriberFunction);
// Subscribes to the sequence with an observer
subscribe(observer: PartialObserver<T>) : Subscription;
// Subscribes to the sequence with callbacks
subscribe(onNext?: Function,
onError?: Function,
onComplete?: Function) : Subscription;
// Returns itself
[Symbol.observable]() : Observable;
// Converts items to an Observable
static of(...items) : Observable;
// Converts an observable or iterable to an Observable
static from(observable) : Observable;
}
export class RxObservable implements Observable {
/** @internal */
protected _isScalar?: boolean = false;
/** @internal */
protected source: Observable<any>;
// ... other private/protected stuff
constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic) {
// ... implementation
}
subscribe() {}
// ... all public methods implemented as usual.
}
The end result of the above should be that you can assign an RxObservable to an Observable and vice-versa. Currently the compiler will complain assigning Rx's Observable to a standard (spec version) of Observable.
We can then export the RxObservable as Observable so we don't break existing code. In the Rx source, we would use RxObservable in value position and Observable in type position.
Subjectis Rx-specific already, so doesn't need any major changes. It will need to be updated to extend and implement the right class/interface based on above changes.