From 6b34f9f9848dd8802c3a641b4b89e04ac9a1f696 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Thu, 1 Mar 2018 21:32:26 -0800 Subject: [PATCH] feat(fromEventPattern): removed resultSelector BREAKING CHANGE: no longer supports a result selector, use `map` instead: `fromEventPattern(fn1, fn2, fn3)` becomes `fromEventPattern(fn1, fn2).pipe(map(fn3))` --- spec/observables/fromEventPattern-spec.ts | 61 --------------------- src/internal/observable/fromEventPattern.ts | 21 +------ 2 files changed, 3 insertions(+), 79 deletions(-) diff --git a/spec/observables/fromEventPattern-spec.ts b/spec/observables/fromEventPattern-spec.ts index b64b1e90f9..4d5bb5adfb 100644 --- a/spec/observables/fromEventPattern-spec.ts +++ b/spec/observables/fromEventPattern-spec.ts @@ -70,65 +70,4 @@ describe('fromEventPattern', () => { done(); }, () => done(new Error('should not be called'))); }); - - it('should accept a selector that maps outgoing values', (done: MochaDone) => { - let target; - const trigger = function (...args) { - if (target) { - target.apply(null, arguments); - } - }; - - const addHandler = (handler: any) => { - target = handler; - }; - const removeHandler = (handler: any) => { - target = null; - }; - const selector = (a: any, b: any) => { - return a + b + '!'; - }; - - fromEventPattern(addHandler, removeHandler, selector).take(1) - .subscribe((x: any) => { - expect(x).to.equal('testme!'); - }, (err: any) => { - done(new Error('should not be called')); - }, () => { - done(); - }); - - trigger('test', 'me'); - }); - - it('should send errors in the selector down the error path', (done: MochaDone) => { - let target; - const trigger = (value: any) => { - if (target) { - target(value); - } - }; - - const addHandler = (handler: any) => { - target = handler; - }; - const removeHandler = (handler: any) => { - target = null; - }; - const selector = (x: any) => { - throw 'bad'; - }; - - fromEventPattern(addHandler, removeHandler, selector) - .subscribe((x: any) => { - done(new Error('should not be called')); - }, (err: any) => { - expect(err).to.equal('bad'); - done(); - }, () => { - done(new Error('should not be called')); - }); - - trigger('test'); - }); }); diff --git a/src/internal/observable/fromEventPattern.ts b/src/internal/observable/fromEventPattern.ts index 82536b6a14..7c7ca14f68 100644 --- a/src/internal/observable/fromEventPattern.ts +++ b/src/internal/observable/fromEventPattern.ts @@ -11,8 +11,7 @@ import { isFunction } from '../util/isFunction'; * * * Creates an Observable by using the `addHandler` and `removeHandler` - * functions to add and remove the handlers, with an optional selector - * function to project the event arguments to a result. The `addHandler` is + * functions to add and remove the handlers. The `addHandler` is * called when the output Observable is subscribed, and `removeHandler` is * called when the Subscription is unsubscribed. * @@ -41,29 +40,15 @@ import { isFunction } from '../util/isFunction'; * 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. - * @param {function(...args: any): T} [selector] An optional function to - * post-process results. It takes the arguments from the event handler and - * should return a single value. * @return {Observable} * @name fromEventPattern */ export function fromEventPattern(addHandler: (handler: Function) => any, - removeHandler?: (handler: Function, signal?: any) => void, - selector?: (...args: any[]) => T) { + removeHandler?: (handler: Function, signal?: any) => void) { return new Observable(subscriber => { - const handler = selector ? (...args: any[]) => { - let result: T; - try { - result = selector(...args); - } catch (err) { - subscriber.error(err); - return; - } - subscriber.next(result); - } : (e: T) => subscriber.next(e); + const handler = (e: T) => subscriber.next(e); let retValue: any; - try { retValue = addHandler(handler); } catch (err) {