Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
926 bytes
|
Line | |
---|
1 | import { Observable } from '../Observable';
|
---|
2 | import { isArray } from '../util/isArray';
|
---|
3 | import { isFunction } from '../util/isFunction';
|
---|
4 | import { map } from '../operators/map';
|
---|
5 | export function fromEventPattern(addHandler, removeHandler, resultSelector) {
|
---|
6 | if (resultSelector) {
|
---|
7 | return fromEventPattern(addHandler, removeHandler).pipe(map(args => isArray(args) ? resultSelector(...args) : resultSelector(args)));
|
---|
8 | }
|
---|
9 | return new Observable(subscriber => {
|
---|
10 | const handler = (...e) => subscriber.next(e.length === 1 ? e[0] : e);
|
---|
11 | let retValue;
|
---|
12 | try {
|
---|
13 | retValue = addHandler(handler);
|
---|
14 | }
|
---|
15 | catch (err) {
|
---|
16 | subscriber.error(err);
|
---|
17 | return undefined;
|
---|
18 | }
|
---|
19 | if (!isFunction(removeHandler)) {
|
---|
20 | return undefined;
|
---|
21 | }
|
---|
22 | return () => removeHandler(handler, retValue);
|
---|
23 | });
|
---|
24 | }
|
---|
25 | //# sourceMappingURL=fromEventPattern.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.