source: trip-planner-front/node_modules/rxjs/internal/observable/fromEvent.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var Observable_1 = require("../Observable");
4var isArray_1 = require("../util/isArray");
5var isFunction_1 = require("../util/isFunction");
6var map_1 = require("../operators/map");
7var toString = (function () { return Object.prototype.toString; })();
8function fromEvent(target, eventName, options, resultSelector) {
9 if (isFunction_1.isFunction(options)) {
10 resultSelector = options;
11 options = undefined;
12 }
13 if (resultSelector) {
14 return fromEvent(target, eventName, options).pipe(map_1.map(function (args) { return isArray_1.isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
15 }
16 return new Observable_1.Observable(function (subscriber) {
17 function handler(e) {
18 if (arguments.length > 1) {
19 subscriber.next(Array.prototype.slice.call(arguments));
20 }
21 else {
22 subscriber.next(e);
23 }
24 }
25 setupSubscription(target, eventName, handler, subscriber, options);
26 });
27}
28exports.fromEvent = fromEvent;
29function setupSubscription(sourceObj, eventName, handler, subscriber, options) {
30 var unsubscribe;
31 if (isEventTarget(sourceObj)) {
32 var source_1 = sourceObj;
33 sourceObj.addEventListener(eventName, handler, options);
34 unsubscribe = function () { return source_1.removeEventListener(eventName, handler, options); };
35 }
36 else if (isJQueryStyleEventEmitter(sourceObj)) {
37 var source_2 = sourceObj;
38 sourceObj.on(eventName, handler);
39 unsubscribe = function () { return source_2.off(eventName, handler); };
40 }
41 else if (isNodeStyleEventEmitter(sourceObj)) {
42 var source_3 = sourceObj;
43 sourceObj.addListener(eventName, handler);
44 unsubscribe = function () { return source_3.removeListener(eventName, handler); };
45 }
46 else if (sourceObj && sourceObj.length) {
47 for (var i = 0, len = sourceObj.length; i < len; i++) {
48 setupSubscription(sourceObj[i], eventName, handler, subscriber, options);
49 }
50 }
51 else {
52 throw new TypeError('Invalid event target');
53 }
54 subscriber.add(unsubscribe);
55}
56function isNodeStyleEventEmitter(sourceObj) {
57 return sourceObj && typeof sourceObj.addListener === 'function' && typeof sourceObj.removeListener === 'function';
58}
59function isJQueryStyleEventEmitter(sourceObj) {
60 return sourceObj && typeof sourceObj.on === 'function' && typeof sourceObj.off === 'function';
61}
62function isEventTarget(sourceObj) {
63 return sourceObj && typeof sourceObj.addEventListener === 'function' && typeof sourceObj.removeEventListener === 'function';
64}
65//# sourceMappingURL=fromEvent.js.map
Note: See TracBrowser for help on using the repository browser.