From a11c76373153cce13e35369c8a4dcab8e0a5c02e Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Fri, 13 Nov 2015 13:58:45 -0800 Subject: [PATCH] fix(Observer): anonymous observers now allow missing handlers Errors were being thrown in situations where a handler was not present on a partial observer fixes #723 --- src/Observer.ts | 8 ++++---- src/Subscriber.ts | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Observer.ts b/src/Observer.ts index 8346678e53..0f990018b3 100644 --- a/src/Observer.ts +++ b/src/Observer.ts @@ -1,6 +1,6 @@ export interface Observer { - next(value: T): void; - error(err?: any): void; - complete(): void; - isUnsubscribed: boolean; + next?: (value: T) => void; + error?: (err?: any) => void; + complete?: () => void; + isUnsubscribed?: boolean; } \ No newline at end of file diff --git a/src/Subscriber.ts b/src/Subscriber.ts index aa97457077..e780f0ba03 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -83,15 +83,24 @@ export class Subscriber extends Subscription implements Observer { } _next(value: T): void { - this.destination.next(value); + const destination = this.destination; + if (destination.next) { + destination.next(value); + } } _error(err: any): void { - this.destination.error(err); + const destination = this.destination; + if (destination.error) { + destination.error(err); + } } _complete(): void { - this.destination.complete(); + const destination = this.destination; + if (destination.complete) { + destination.complete(); + } } next(value?: T): void {