Skip to content

Instantly share code, notes, and snippets.

protected _next(value: T): void {
this.destination.next(value);
}
protected _error(err: any): void {
this.destination.error(err);
this.unsubscribe();
}
protected _complete(): void {
unsubscribe(): void {
if (this.closed) {
return;
}
this.isStopped = true;
super.unsubscribe();
}
class Observable<T> implements Subscribable<T> {...}
export interface Subscribable<T> {
subscribe(observer?: PartialObserver<T>): Unsubscribable;
}
type PartialObserver<T> = NextObserver<T> | ErrorObserver<T> | CompletionObserver<T>;
class Observable<T> implements Subscribable<T> {
...
constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic) {
if (subscribe) {
this._subscribe = subscribe;
}
}
}
subscribe(observer?: PartialObserver<T>): Subscription;
subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void) | null,
error?: ((error: any) => void) | null,
complete?: (() => void) | null): Subscription {
const sink = toSubscriber(observerOrNext, error, complete);
sink.add(
this._subscribe(sink) // call fn wicth we pass to constructor
);
class Customer {
checkEmail(news) {
// here we take a look on news and make a decision buy or not
}
findAnotherShop() {
// search for a new shop for us
}
checkOrder() {