source: trip-planner-front/node_modules/rxjs/_esm5/internal/observable/bindNodeCallback.js

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

initial commit

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/** PURE_IMPORTS_START _Observable,_AsyncSubject,_operators_map,_util_canReportError,_util_isScheduler,_util_isArray PURE_IMPORTS_END */
2import { Observable } from '../Observable';
3import { AsyncSubject } from '../AsyncSubject';
4import { map } from '../operators/map';
5import { canReportError } from '../util/canReportError';
6import { isScheduler } from '../util/isScheduler';
7import { isArray } from '../util/isArray';
8export function bindNodeCallback(callbackFunc, resultSelector, scheduler) {
9 if (resultSelector) {
10 if (isScheduler(resultSelector)) {
11 scheduler = resultSelector;
12 }
13 else {
14 return function () {
15 var args = [];
16 for (var _i = 0; _i < arguments.length; _i++) {
17 args[_i] = arguments[_i];
18 }
19 return bindNodeCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map(function (args) { return isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
20 };
21 }
22 }
23 return function () {
24 var args = [];
25 for (var _i = 0; _i < arguments.length; _i++) {
26 args[_i] = arguments[_i];
27 }
28 var params = {
29 subject: undefined,
30 args: args,
31 callbackFunc: callbackFunc,
32 scheduler: scheduler,
33 context: this,
34 };
35 return new Observable(function (subscriber) {
36 var context = params.context;
37 var subject = params.subject;
38 if (!scheduler) {
39 if (!subject) {
40 subject = params.subject = new AsyncSubject();
41 var handler = function () {
42 var innerArgs = [];
43 for (var _i = 0; _i < arguments.length; _i++) {
44 innerArgs[_i] = arguments[_i];
45 }
46 var err = innerArgs.shift();
47 if (err) {
48 subject.error(err);
49 return;
50 }
51 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
52 subject.complete();
53 };
54 try {
55 callbackFunc.apply(context, args.concat([handler]));
56 }
57 catch (err) {
58 if (canReportError(subject)) {
59 subject.error(err);
60 }
61 else {
62 console.warn(err);
63 }
64 }
65 }
66 return subject.subscribe(subscriber);
67 }
68 else {
69 return scheduler.schedule(dispatch, 0, { params: params, subscriber: subscriber, context: context });
70 }
71 });
72 };
73}
74function dispatch(state) {
75 var _this = this;
76 var params = state.params, subscriber = state.subscriber, context = state.context;
77 var callbackFunc = params.callbackFunc, args = params.args, scheduler = params.scheduler;
78 var subject = params.subject;
79 if (!subject) {
80 subject = params.subject = new AsyncSubject();
81 var handler = function () {
82 var innerArgs = [];
83 for (var _i = 0; _i < arguments.length; _i++) {
84 innerArgs[_i] = arguments[_i];
85 }
86 var err = innerArgs.shift();
87 if (err) {
88 _this.add(scheduler.schedule(dispatchError, 0, { err: err, subject: subject }));
89 }
90 else {
91 var value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
92 _this.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
93 }
94 };
95 try {
96 callbackFunc.apply(context, args.concat([handler]));
97 }
98 catch (err) {
99 this.add(scheduler.schedule(dispatchError, 0, { err: err, subject: subject }));
100 }
101 }
102 this.add(subject.subscribe(subscriber));
103}
104function dispatchNext(arg) {
105 var value = arg.value, subject = arg.subject;
106 subject.next(value);
107 subject.complete();
108}
109function dispatchError(arg) {
110 var err = arg.err, subject = arg.subject;
111 subject.error(err);
112}
113//# sourceMappingURL=bindNodeCallback.js.map
Note: See TracBrowser for help on using the repository browser.