source: trip-planner-front/node_modules/rxjs/_esm2015/internal/observable/bindCallback.js@ 571e0df

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: 2.8 KB
Line 
1import { Observable } from '../Observable';
2import { AsyncSubject } from '../AsyncSubject';
3import { map } from '../operators/map';
4import { canReportError } from '../util/canReportError';
5import { isArray } from '../util/isArray';
6import { isScheduler } from '../util/isScheduler';
7export function bindCallback(callbackFunc, resultSelector, scheduler) {
8 if (resultSelector) {
9 if (isScheduler(resultSelector)) {
10 scheduler = resultSelector;
11 }
12 else {
13 return (...args) => bindCallback(callbackFunc, scheduler)(...args).pipe(map((args) => isArray(args) ? resultSelector(...args) : resultSelector(args)));
14 }
15 }
16 return function (...args) {
17 const context = this;
18 let subject;
19 const params = {
20 context,
21 subject,
22 callbackFunc,
23 scheduler,
24 };
25 return new Observable(subscriber => {
26 if (!scheduler) {
27 if (!subject) {
28 subject = new AsyncSubject();
29 const handler = (...innerArgs) => {
30 subject.next(innerArgs.length <= 1 ? innerArgs[0] : innerArgs);
31 subject.complete();
32 };
33 try {
34 callbackFunc.apply(context, [...args, handler]);
35 }
36 catch (err) {
37 if (canReportError(subject)) {
38 subject.error(err);
39 }
40 else {
41 console.warn(err);
42 }
43 }
44 }
45 return subject.subscribe(subscriber);
46 }
47 else {
48 const state = {
49 args, subscriber, params,
50 };
51 return scheduler.schedule(dispatch, 0, state);
52 }
53 });
54 };
55}
56function dispatch(state) {
57 const self = this;
58 const { args, subscriber, params } = state;
59 const { callbackFunc, context, scheduler } = params;
60 let { subject } = params;
61 if (!subject) {
62 subject = params.subject = new AsyncSubject();
63 const handler = (...innerArgs) => {
64 const value = innerArgs.length <= 1 ? innerArgs[0] : innerArgs;
65 this.add(scheduler.schedule(dispatchNext, 0, { value, subject }));
66 };
67 try {
68 callbackFunc.apply(context, [...args, handler]);
69 }
70 catch (err) {
71 subject.error(err);
72 }
73 }
74 this.add(subject.subscribe(subscriber));
75}
76function dispatchNext(state) {
77 const { value, subject } = state;
78 subject.next(value);
79 subject.complete();
80}
81function dispatchError(state) {
82 const { err, subject } = state;
83 subject.error(err);
84}
85//# sourceMappingURL=bindCallback.js.map
Note: See TracBrowser for help on using the repository browser.