github-pages-deploy-action/node_modules/rxjs/_esm5/internal/observable/fromEventPattern.js

33 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-03-07 11:45:40 +08:00
/** PURE_IMPORTS_START _Observable,_util_isArray,_util_isFunction,_operators_map PURE_IMPORTS_END */
import { Observable } from '../Observable';
import { isArray } from '../util/isArray';
import { isFunction } from '../util/isFunction';
import { map } from '../operators/map';
export function fromEventPattern(addHandler, removeHandler, resultSelector) {
if (resultSelector) {
return fromEventPattern(addHandler, removeHandler).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
}
return new Observable(function (subscriber) {
var handler = function () {
var e = [];
for (var _i = 0; _i < arguments.length; _i++) {
e[_i] = arguments[_i];
}
return subscriber.next(e.length === 1 ? e[0] : e);
};
var retValue;
try {
retValue = addHandler(handler);
}
catch (err) {
subscriber.error(err);
return undefined;
}
if (!isFunction(removeHandler)) {
return undefined;
}
return function () { return removeHandler(handler, retValue); };
});
}
//# sourceMappingURL=fromEventPattern.js.map