Skip to content

Commit

Permalink
feat(fromEventPattern): support optional removeHandler
Browse files Browse the repository at this point in the history
- relates to #2088
  • Loading branch information
kwonoj committed Jan 15, 2017
1 parent 01d0622 commit 86960c2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/observable/FromEventPatternObservable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isFunction } from '../util/isFunction';
import { Observable } from '../Observable';
import { Subscription } from '../Subscription';
import { Subscriber } from '../Subscriber';
Expand Down Expand Up @@ -45,7 +46,7 @@ export class FromEventPatternObservable<T> extends Observable<T> {
* @param {function(handler: Function): any} addHandler A function that takes
* a `handler` function as argument and attaches it somehow to the actual
* source of events.
* @param {function(handler: Function, signal?: any): void} removeHandler A function that
* @param {function(handler: Function, signal?: any): void} [removeHandler] An optional function that
* takes a `handler` function as argument and removes it in case it was
* previously attached using `addHandler`. if addHandler returns signal to teardown when remove,
* removeHandler function will forward it.
Expand All @@ -58,13 +59,13 @@ export class FromEventPatternObservable<T> extends Observable<T> {
* @owner Observable
*/
static create<T>(addHandler: (handler: Function) => any,
removeHandler: (handler: Function, signal?: any) => void,
removeHandler?: (handler: Function, signal?: any) => void,
selector?: (...args: Array<any>) => T) {
return new FromEventPatternObservable(addHandler, removeHandler, selector);
}

constructor(private addHandler: (handler: Function) => any,
private removeHandler: (handler: Function, signal?: any) => void,
private removeHandler?: (handler: Function, signal?: any) => void,
private selector?: (...args: Array<any>) => T) {
super();
}
Expand All @@ -78,6 +79,10 @@ export class FromEventPatternObservable<T> extends Observable<T> {

const retValue = this._callAddHandler(handler, subscriber);

if (!isFunction(removeHandler)) {
return;
}

subscriber.add(new Subscription(() => {
//TODO: determine whether or not to forward to error handler
removeHandler(handler, retValue) ;
Expand Down

0 comments on commit 86960c2

Please sign in to comment.