source: trip-planner-front/node_modules/rxjs/internal/observable/bindCallback.js@ ceaed42

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

initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var Observable_1 = require("../Observable");
4var AsyncSubject_1 = require("../AsyncSubject");
5var map_1 = require("../operators/map");
6var canReportError_1 = require("../util/canReportError");
7var isArray_1 = require("../util/isArray");
8var isScheduler_1 = require("../util/isScheduler");
9function bindCallback(callbackFunc, resultSelector, scheduler) {
10 if (resultSelector) {
11 if (isScheduler_1.isScheduler(resultSelector)) {
12 scheduler = resultSelector;
13 }
14 else {
15 return function () {
16 var args = [];
17 for (var _i = 0; _i < arguments.length; _i++) {
18 args[_i] = arguments[_i];
19 }
20 return bindCallback(callbackFunc, scheduler).apply(void 0, args).pipe(map_1.map(function (args) { return isArray_1.isArray(args) ? resultSelector.apply(void 0, args) : resultSelector(args); }));
21 };
22 }
23 }
24 return function () {
25 var args = [];
26 for (var _i = 0; _i < arguments.length; _i++) {
27 args[_i] = arguments[_i];
28 }
29 var context = this;
30 var subject;
31 var params = {
32 context: context,
33 subject: subject,
34 callbackFunc: callbackFunc,
35 scheduler: scheduler,
36 };
37 return new Observable_1.Observable(function (subscriber) {
38 if (!scheduler) {
39 if (!subject) {
40 subject = new AsyncSubject_1.AsyncSubject();
41 var handler = function () {
42 var innerArgs = [];
43 for (var _i = 0; _i < arguments.length; _i++) {
44 innerArgs[_i] = arguments[_i];
45 }
46 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
47 subject.complete();
48 };
49 try {
50 callbackFunc.apply(context, args.concat([handler]));
51 }
52 catch (err) {
53 if (canReportError_1.canReportError(subject)) {
54 subject.error(err);
55 }
56 else {
57 console.warn(err);
58 }
59 }
60 }
61 return subject.subscribe(subscriber);
62 }
63 else {
64 var state = {
65 args: args, subscriber: subscriber, params: params,
66 };
67 return scheduler.schedule(dispatch, 0, state);
68 }
69 });
70 };
71}
72exports.bindCallback = bindCallback;
73function dispatch(state) {
74 var _this = this;
75 var self = this;
76 var args = state.args, subscriber = state.subscriber, params = state.params;
77 var callbackFunc = params.callbackFunc, context = params.context, scheduler = params.scheduler;
78 var subject = params.subject;
79 if (!subject) {
80 subject = params.subject = new AsyncSubject_1.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 value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
87 _this.add(scheduler.schedule(dispatchNext, 0, { value: value, subject: subject }));
88 };
89 try {
90 callbackFunc.apply(context, args.concat([handler]));
91 }
92 catch (err) {
93 subject.error(err);
94 }
95 }
96 this.add(subject.subscribe(subscriber));
97}
98function dispatchNext(state) {
99 var value = state.value, subject = state.subject;
100 subject.next(value);
101 subject.complete();
102}
103function dispatchError(state) {
104 var err = state.err, subject = state.subject;
105 subject.error(err);
106}
107//# sourceMappingURL=bindCallback.js.map
Note: See TracBrowser for help on using the repository browser.