Skip to content

Instantly share code, notes, and snippets.

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() {
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 Observable<T> implements Subscribable<T> {
...
constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic) {
if (subscribe) {
this._subscribe = subscribe;
}
}
}
class Observable<T> implements Subscribable<T> {...}
export interface Subscribable<T> {
subscribe(observer?: PartialObserver<T>): Unsubscribable;
}
type PartialObserver<T> = NextObserver<T> | ErrorObserver<T> | CompletionObserver<T>;
unsubscribe(): void {
if (this.closed) {
return;
}
this.isStopped = true;
super.unsubscribe();
}
protected _next(value: T): void {
this.destination.next(value);
}
protected _error(err: any): void {
this.destination.error(err);
this.unsubscribe();
}
protected _complete(): void {
next(value?: T): void {
if (!this.isStopped) {
this._next(value!);
}
}
error(err?: any): void {
if (!this.isStopped) {
this.isStopped = true;
this._error(err);
protected destination: Observer<any> | Subscriber<any>;
constructor(destinationOrNext?: PartialObserver<any> | ((value: T) => void) | null,
error?: ((e?: any) => void) | null,
complete?: (() => void) | null) {
super();
switch (arguments.length) {
case A:
this.destination = emptyObserver;
class Subscriber<T> extends Subscription implements Observer<T> {...}
interface Observer<T> {
closed?: boolean;
next: (value: T) => void;
error: (err: any) => void;
complete: () => void;
}
/** @internal */
protected _parentOrParents: Subscription | Subscription[] | null = null;
/** @internal */
private _subscriptions: SubscriptionLike[] | null = null;