This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Observable<T> implements Subscribable<T> { | |
... | |
constructor(subscribe?: (this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic) { | |
if (subscribe) { | |
this._subscribe = subscribe; | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Observable<T> implements Subscribable<T> {...} | |
export interface Subscribable<T> { | |
subscribe(observer?: PartialObserver<T>): Unsubscribable; | |
} | |
type PartialObserver<T> = NextObserver<T> | ErrorObserver<T> | CompletionObserver<T>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsubscribe(): void { | |
if (this.closed) { | |
return; | |
} | |
this.isStopped = true; | |
super.unsubscribe(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected _next(value: T): void { | |
this.destination.next(value); | |
} | |
protected _error(err: any): void { | |
this.destination.error(err); | |
this.unsubscribe(); | |
} | |
protected _complete(): void { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
next(value?: T): void { | |
if (!this.isStopped) { | |
this._next(value!); | |
} | |
} | |
error(err?: any): void { | |
if (!this.isStopped) { | |
this.isStopped = true; | |
this._error(err); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Subscriber<T> extends Subscription implements Observer<T> {...} | |
interface Observer<T> { | |
closed?: boolean; | |
next: (value: T) => void; | |
error: (err: any) => void; | |
complete: () => void; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @internal */ | |
protected _parentOrParents: Subscription | Subscription[] | null = null; | |
/** @internal */ | |
private _subscriptions: SubscriptionLike[] | null = null; |
NewerOlder