flinker 1.0.0 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,481 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import { RXEmitter, RXJustComplete } from './RXPublisher.js';
17
+ import { RXSubscriber } from './RXSubscriber.js';
18
+ var RXOperator = /** @class */ (function () {
19
+ function RXOperator(pipeline) {
20
+ this.type = 'operator';
21
+ //--------------------------------------
22
+ // isComplete
23
+ //--------------------------------------
24
+ this._isComplete = false;
25
+ this.pipeline = pipeline;
26
+ }
27
+ Object.defineProperty(RXOperator.prototype, "isComplete", {
28
+ get: function () { return this._isComplete; },
29
+ enumerable: false,
30
+ configurable: true
31
+ });
32
+ //--------------------------------------
33
+ // RXSender Protocol
34
+ //--------------------------------------
35
+ RXOperator.prototype.send = function (value, broadcast) {
36
+ var _a;
37
+ if (!this.isComplete) {
38
+ (_a = this.child) === null || _a === void 0 ? void 0 : _a.send(value, broadcast);
39
+ }
40
+ };
41
+ RXOperator.prototype.sendError = function (e, broadcast) {
42
+ var _a;
43
+ if (!this.isComplete) {
44
+ (_a = this.child) === null || _a === void 0 ? void 0 : _a.sendError(e, broadcast);
45
+ }
46
+ };
47
+ RXOperator.prototype.sendComplete = function (broadcast) {
48
+ var _a;
49
+ if (!this.isComplete) {
50
+ this._isComplete = true;
51
+ (_a = this.child) === null || _a === void 0 ? void 0 : _a.sendComplete(broadcast);
52
+ }
53
+ };
54
+ //--------------------------------------
55
+ // OPERATORS
56
+ //--------------------------------------
57
+ RXOperator.prototype.skipFirst = function () {
58
+ return this.addChild(new RXSkipFirst(this.pipeline));
59
+ };
60
+ RXOperator.prototype.skipNullable = function () {
61
+ return this.addChild(new RXSkipNullable(this.pipeline));
62
+ };
63
+ RXOperator.prototype.removeDuplicates = function (value) {
64
+ return this.addChild(new RXRemoveDuplicates(this.pipeline, value));
65
+ };
66
+ RXOperator.prototype.debounce = function (ms) {
67
+ return this.addChild(new RXDebounce(this.pipeline, ms));
68
+ };
69
+ RXOperator.prototype.map = function (f) {
70
+ return this.addChild(new RXMap(this.pipeline, f));
71
+ };
72
+ RXOperator.prototype.flatMap = function (f) {
73
+ return this.addChild(new RXFlatMap(this.pipeline, f));
74
+ };
75
+ RXOperator.prototype.forEach = function (f) {
76
+ return this.addChild(new RXForEach(this.pipeline, f));
77
+ };
78
+ RXOperator.prototype.sequent = function (f) {
79
+ return this.addChild(new RXSequent(this.pipeline, f));
80
+ };
81
+ RXOperator.prototype.parallel = function (f) {
82
+ return this.addChild(new RXParallel(this.pipeline, f));
83
+ };
84
+ RXOperator.prototype.filter = function (predicate) {
85
+ return this.addChild(new RXFilter(this.pipeline, predicate));
86
+ };
87
+ RXOperator.prototype.spread = function () {
88
+ return this.addChild(new RXSpread(this.pipeline));
89
+ };
90
+ RXOperator.prototype.replaceError = function (replaceWith) {
91
+ return this.addChild(new RXReplaceError(this.pipeline, replaceWith));
92
+ };
93
+ RXOperator.prototype.addChild = function (op) {
94
+ this.child = op;
95
+ return op;
96
+ };
97
+ //--------------------------------------
98
+ // Output
99
+ //--------------------------------------
100
+ RXOperator.prototype.fork = function () {
101
+ var subscriber = new RXSubscriber(this.pipeline);
102
+ this.child = subscriber;
103
+ var dispatcher = new RXEmitter();
104
+ subscriber.onReceive(function (v) { dispatcher.send(v); });
105
+ subscriber.onError(function (e) { dispatcher.sendError(e); });
106
+ subscriber.onComplete(function () { dispatcher.sendComplete(); });
107
+ subscriber.subscribe();
108
+ return dispatcher.asObservable;
109
+ };
110
+ RXOperator.prototype.onReceive = function (f) {
111
+ var subscriber = new RXSubscriber(this.pipeline);
112
+ this.child = subscriber;
113
+ return subscriber.onReceive(f);
114
+ };
115
+ RXOperator.prototype.onError = function (f) {
116
+ var subscriber = new RXSubscriber(this.pipeline);
117
+ this.child = subscriber;
118
+ return subscriber.onError(f);
119
+ };
120
+ RXOperator.prototype.onComplete = function (f) {
121
+ var subscriber = new RXSubscriber(this.pipeline);
122
+ this.child = subscriber;
123
+ return subscriber.onComplete(f);
124
+ };
125
+ return RXOperator;
126
+ }());
127
+ export { RXOperator };
128
+ //--------------------------------------
129
+ // RXMap
130
+ //--------------------------------------
131
+ var RXMap = /** @class */ (function (_super) {
132
+ __extends(RXMap, _super);
133
+ function RXMap(pipe, mapper) {
134
+ var _this = _super.call(this, pipe) || this;
135
+ _this.mapper = mapper;
136
+ return _this;
137
+ }
138
+ RXMap.prototype.send = function (value, broadcast) {
139
+ var newValue = this.mapper(value);
140
+ _super.prototype.send.call(this, newValue, broadcast);
141
+ };
142
+ return RXMap;
143
+ }(RXOperator));
144
+ export { RXMap };
145
+ //--------------------------------------
146
+ // RXFlatMap
147
+ //--------------------------------------
148
+ var RXFlatMap = /** @class */ (function (_super) {
149
+ __extends(RXFlatMap, _super);
150
+ function RXFlatMap(pipe, mapper) {
151
+ var _this = _super.call(this, pipe) || this;
152
+ _this.mapper = mapper;
153
+ return _this;
154
+ }
155
+ RXFlatMap.prototype.send = function (value, broadcast) {
156
+ var _this = this;
157
+ if (this.isComplete)
158
+ return;
159
+ this.mapper(value).pipe()
160
+ .onReceive(function (v) {
161
+ _super.prototype.send.call(_this, v, broadcast);
162
+ })
163
+ .onError(function (e) {
164
+ _this.sendError(e, broadcast);
165
+ })
166
+ .subscribe();
167
+ };
168
+ return RXFlatMap;
169
+ }(RXOperator));
170
+ export { RXFlatMap };
171
+ var RXForEach = /** @class */ (function (_super) {
172
+ __extends(RXForEach, _super);
173
+ function RXForEach(pipe, mapper) {
174
+ var _this = _super.call(this, pipe) || this;
175
+ _this.buffer = Array();
176
+ _this.willComplete = false;
177
+ _this.willCompleteBroadcast = false;
178
+ _this.curOp = new RXJustComplete();
179
+ _this.mapper = mapper;
180
+ return _this;
181
+ }
182
+ RXForEach.prototype.send = function (value, broadcast) {
183
+ this.buffer.push({ hasError: false, value: value, broadcast: broadcast });
184
+ this.processNext();
185
+ };
186
+ RXForEach.prototype.sendError = function (error, broadcast) {
187
+ this.buffer.push({ hasError: true, error: error, broadcast: broadcast });
188
+ this.processNext();
189
+ };
190
+ RXForEach.prototype.sendComplete = function (broadcast) {
191
+ this.willComplete = true;
192
+ this.willCompleteBroadcast || (this.willCompleteBroadcast = broadcast);
193
+ this.processNext();
194
+ };
195
+ RXForEach.prototype.processNext = function () {
196
+ var _this = this;
197
+ if (!this.curOp.isComplete)
198
+ return;
199
+ var notification = this.buffer.shift();
200
+ if (notification) {
201
+ if (notification.hasError) {
202
+ _super.prototype.sendError.call(this, notification.error, notification.broadcast);
203
+ this.processNext();
204
+ }
205
+ else if (notification.value !== undefined) {
206
+ this.curOp = this.mapper(notification.value);
207
+ this.curOp.pipe()
208
+ .onReceive(function (v) {
209
+ _super.prototype.send.call(_this, v, notification.broadcast);
210
+ })
211
+ .onError(function (e) {
212
+ _super.prototype.sendError.call(_this, e, notification.broadcast);
213
+ })
214
+ .onComplete(function () { _this.processNext(); })
215
+ .subscribe();
216
+ }
217
+ else {
218
+ this.processNext();
219
+ }
220
+ }
221
+ else {
222
+ if (this.willComplete)
223
+ _super.prototype.sendComplete.call(this, this.willCompleteBroadcast);
224
+ }
225
+ };
226
+ return RXForEach;
227
+ }(RXOperator));
228
+ export { RXForEach };
229
+ var RXSequent = /** @class */ (function (_super) {
230
+ __extends(RXSequent, _super);
231
+ function RXSequent(pipe, mapper) {
232
+ var _this = _super.call(this, pipe) || this;
233
+ _this.buffer = Array();
234
+ _this.willComplete = false;
235
+ _this.willCompleteBroadcast = false;
236
+ _this.curOp = new RXJustComplete();
237
+ _this.mapper = mapper;
238
+ return _this;
239
+ }
240
+ RXSequent.prototype.send = function (value, broadcast) {
241
+ this.buffer.push({ hasError: false, value: value, broadcast: broadcast });
242
+ this.processNext();
243
+ };
244
+ RXSequent.prototype.sendError = function (error, broadcast) {
245
+ this.buffer.push({ hasError: true, error: error, broadcast: broadcast });
246
+ this.processNext();
247
+ };
248
+ RXSequent.prototype.sendComplete = function (broadcast) {
249
+ this.willComplete = true;
250
+ this.willCompleteBroadcast || (this.willCompleteBroadcast = broadcast);
251
+ this.processNext();
252
+ };
253
+ RXSequent.prototype.processNext = function () {
254
+ var _this = this;
255
+ if (!this.curOp.isComplete)
256
+ return;
257
+ var notification = this.buffer.shift();
258
+ if (notification) {
259
+ if (notification.hasError) {
260
+ _super.prototype.sendError.call(this, notification.error, notification.broadcast);
261
+ this.processNext();
262
+ }
263
+ else if (notification.value !== undefined) {
264
+ this.curOp = this.mapper(notification.value);
265
+ this.curOp.pipe()
266
+ .onReceive(function (v) {
267
+ _super.prototype.send.call(_this, v, notification.broadcast);
268
+ })
269
+ .onError(function (e) {
270
+ _super.prototype.sendError.call(_this, e, notification.broadcast);
271
+ })
272
+ .onComplete(function () { _this.processNext(); })
273
+ .subscribe();
274
+ }
275
+ else {
276
+ this.processNext();
277
+ }
278
+ }
279
+ else {
280
+ if (this.willComplete)
281
+ _super.prototype.sendComplete.call(this, this.willCompleteBroadcast);
282
+ }
283
+ };
284
+ return RXSequent;
285
+ }(RXOperator));
286
+ export { RXSequent };
287
+ //--------------------------------------
288
+ // RXParallel
289
+ //--------------------------------------
290
+ var RXParallel = /** @class */ (function (_super) {
291
+ __extends(RXParallel, _super);
292
+ function RXParallel(pipe, mapper) {
293
+ var _this = _super.call(this, pipe) || this;
294
+ _this.willComplete = false;
295
+ _this.willCompleteBroadcast = false;
296
+ _this.activeOperations = 0;
297
+ _this.mapper = mapper;
298
+ return _this;
299
+ }
300
+ RXParallel.prototype.send = function (value, broadcast) {
301
+ var _this = this;
302
+ this.activeOperations++;
303
+ this.mapper(value).pipe()
304
+ .onReceive(function (v) {
305
+ _super.prototype.send.call(_this, v, broadcast);
306
+ })
307
+ .onError(function (e) {
308
+ _super.prototype.sendError.call(_this, e, broadcast);
309
+ })
310
+ .onComplete(function () {
311
+ _this.activeOperations--;
312
+ if (_this.activeOperations === 0 && _this.willComplete)
313
+ _super.prototype.sendComplete.call(_this, _this.willCompleteBroadcast);
314
+ })
315
+ .subscribe();
316
+ };
317
+ RXParallel.prototype.sendComplete = function (broadcast) {
318
+ this.willComplete = true;
319
+ this.willCompleteBroadcast || (this.willCompleteBroadcast = broadcast);
320
+ if (this.activeOperations === 0) {
321
+ _super.prototype.sendComplete.call(this, broadcast);
322
+ }
323
+ };
324
+ return RXParallel;
325
+ }(RXOperator));
326
+ export { RXParallel };
327
+ //--------------------------------------
328
+ // RXFilter
329
+ //--------------------------------------
330
+ var RXFilter = /** @class */ (function (_super) {
331
+ __extends(RXFilter, _super);
332
+ function RXFilter(pipe, predicate) {
333
+ var _this = _super.call(this, pipe) || this;
334
+ _this.predicate = predicate;
335
+ return _this;
336
+ }
337
+ RXFilter.prototype.send = function (value, broadcast) {
338
+ if (this.predicate(value))
339
+ _super.prototype.send.call(this, value, broadcast);
340
+ };
341
+ return RXFilter;
342
+ }(RXOperator));
343
+ export { RXFilter };
344
+ //--------------------------------------
345
+ // RXSpread
346
+ //--------------------------------------
347
+ var RXSpread = /** @class */ (function (_super) {
348
+ __extends(RXSpread, _super);
349
+ function RXSpread() {
350
+ return _super !== null && _super.apply(this, arguments) || this;
351
+ }
352
+ RXSpread.prototype.send = function (value, broadcast) {
353
+ var _this = this;
354
+ if (Array.isArray(value)) {
355
+ value.forEach(function (v) {
356
+ _super.prototype.send.call(_this, v, broadcast);
357
+ });
358
+ }
359
+ else
360
+ _super.prototype.send.call(this, value, broadcast);
361
+ };
362
+ return RXSpread;
363
+ }(RXOperator));
364
+ export { RXSpread };
365
+ //--------------------------------------
366
+ // RXSkipFirst
367
+ //--------------------------------------
368
+ //ignore value emitted just after registration of a new subscriber
369
+ var RXSkipFirst = /** @class */ (function (_super) {
370
+ __extends(RXSkipFirst, _super);
371
+ function RXSkipFirst() {
372
+ return _super !== null && _super.apply(this, arguments) || this;
373
+ }
374
+ RXSkipFirst.prototype.send = function (value, broadcast) {
375
+ if (broadcast)
376
+ _super.prototype.send.call(this, value, broadcast);
377
+ };
378
+ return RXSkipFirst;
379
+ }(RXOperator));
380
+ export { RXSkipFirst };
381
+ //--------------------------------------
382
+ // RXSkipNullable
383
+ //--------------------------------------
384
+ var RXSkipNullable = /** @class */ (function (_super) {
385
+ __extends(RXSkipNullable, _super);
386
+ function RXSkipNullable() {
387
+ return _super !== null && _super.apply(this, arguments) || this;
388
+ }
389
+ RXSkipNullable.prototype.send = function (value, broadcast) {
390
+ if (value !== null && value !== undefined)
391
+ _super.prototype.send.call(this, value, broadcast);
392
+ };
393
+ return RXSkipNullable;
394
+ }(RXOperator));
395
+ export { RXSkipNullable };
396
+ //--------------------------------------
397
+ // RXRemoveDuplicates
398
+ //--------------------------------------
399
+ var RXRemoveDuplicates = /** @class */ (function (_super) {
400
+ __extends(RXRemoveDuplicates, _super);
401
+ function RXRemoveDuplicates(pipe, value) {
402
+ var _this = _super.call(this, pipe) || this;
403
+ _this.prevValue = undefined;
404
+ _this.prevValue = value;
405
+ return _this;
406
+ }
407
+ RXRemoveDuplicates.prototype.send = function (value, broadcast) {
408
+ if (this.prevValue !== value) {
409
+ this.prevValue = value;
410
+ _super.prototype.send.call(this, value, broadcast);
411
+ }
412
+ };
413
+ return RXRemoveDuplicates;
414
+ }(RXOperator));
415
+ export { RXRemoveDuplicates };
416
+ var RXDebounce = /** @class */ (function (_super) {
417
+ __extends(RXDebounce, _super);
418
+ function RXDebounce(pipe, ms) {
419
+ var _this = _super.call(this, pipe) || this;
420
+ _this.buffer = Array();
421
+ _this.willComplete = false;
422
+ _this.willCompleteBroadcast = false;
423
+ _this.timeoutId = undefined;
424
+ _this.ms = ms;
425
+ return _this;
426
+ }
427
+ RXDebounce.prototype.startTimer = function () {
428
+ var _this = this;
429
+ if (this.timeoutId)
430
+ return;
431
+ this.timeoutId = setTimeout(function () {
432
+ _this.timeoutId = undefined;
433
+ for (var i = _this.buffer.length - 1; i >= 0; i--) {
434
+ var notification = _this.buffer[i];
435
+ if (notification.hasError) {
436
+ _super.prototype.sendError.call(_this, notification.error, notification.broadcast);
437
+ }
438
+ else {
439
+ _super.prototype.send.call(_this, notification.value, notification.broadcast);
440
+ }
441
+ //if (notification.broadcast) break
442
+ break;
443
+ }
444
+ _this.buffer.length = 0;
445
+ if (_this.willComplete)
446
+ _super.prototype.sendComplete.call(_this, _this.willCompleteBroadcast);
447
+ }, this.ms);
448
+ };
449
+ RXDebounce.prototype.send = function (value, broadcast) {
450
+ this.buffer.push({ hasError: false, value: value, broadcast: broadcast });
451
+ this.startTimer();
452
+ };
453
+ RXDebounce.prototype.sendError = function (error, broadcast) {
454
+ this.buffer.push({ hasError: true, error: error, broadcast: broadcast });
455
+ this.startTimer();
456
+ };
457
+ RXDebounce.prototype.sendComplete = function (broadcast) {
458
+ this.willComplete = true;
459
+ this.willCompleteBroadcast || (this.willCompleteBroadcast = broadcast);
460
+ this.startTimer();
461
+ };
462
+ return RXDebounce;
463
+ }(RXOperator));
464
+ export { RXDebounce };
465
+ //--------------------------------------
466
+ // RXReplaceError
467
+ //--------------------------------------
468
+ var RXReplaceError = /** @class */ (function (_super) {
469
+ __extends(RXReplaceError, _super);
470
+ function RXReplaceError(pipe, replaceWith) {
471
+ var _this = _super.call(this, pipe) || this;
472
+ _this.replaceWith = replaceWith;
473
+ return _this;
474
+ }
475
+ RXReplaceError.prototype.sendError = function (e, broadcast) {
476
+ var value = this.replaceWith(e);
477
+ value ? this.send(value, broadcast) : _super.prototype.sendError.call(this, e, broadcast);
478
+ };
479
+ return RXReplaceError;
480
+ }(RXOperator));
481
+ export { RXReplaceError };
@@ -0,0 +1,24 @@
1
+ import { RXOperator } from './RXOperator.js';
2
+ var RXPipeline = /** @class */ (function () {
3
+ function RXPipeline(dispatcher) {
4
+ this.type = 'pipeline';
5
+ this.child = new RXOperator(this);
6
+ this.dispatcher = dispatcher;
7
+ }
8
+ Object.defineProperty(RXPipeline.prototype, "asOperator", {
9
+ get: function () { return this.child; },
10
+ enumerable: false,
11
+ configurable: true
12
+ });
13
+ RXPipeline.prototype.send = function (value, broadcast) {
14
+ this.child.send(value, broadcast);
15
+ };
16
+ RXPipeline.prototype.sendError = function (e, broadcast) {
17
+ this.child.sendError(e, broadcast);
18
+ };
19
+ RXPipeline.prototype.sendComplete = function (broadcast) {
20
+ this.child.sendComplete(broadcast);
21
+ };
22
+ return RXPipeline;
23
+ }());
24
+ export { RXPipeline };