1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | 1 1 3 1 24 1 1 1 1 1 1 1 1 12 12 26 12 2 12 12 1 1 12 12 12 1 12 1 1 1 1 12 12 12 12 12 12 12 12 24 12 24 24 1 46 46 46 26 26 18 1 1 17 11 11 11 11 11 4 4 4 7 1 1 | 'use strict'; exports.__esModule = true; exports['default'] = withLatestFrom; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _utilTryCatch = require('../util/tryCatch'); var _utilTryCatch2 = _interopRequireDefault(_utilTryCatch); var _utilErrorObject = require('../util/errorObject'); var _OuterSubscriber2 = require('../OuterSubscriber'); var _OuterSubscriber3 = _interopRequireDefault(_OuterSubscriber2); var _utilSubscribeToResult = require('../util/subscribeToResult'); var _utilSubscribeToResult2 = _interopRequireDefault(_utilSubscribeToResult); /** * @param {Observable} observables the observables to get the latest values from. * @param {Function} [project] optional projection function for merging values together. Receives all values in order * of observables passed. (e.g. `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not passed, arrays * will be returned. * @description merges each value from an observable with the latest values from the other passed observables. * All observables must emit at least one value before the resulting observable will emit * * #### example * ``` * A.withLatestFrom(B, C) * * A: ----a-----------------b---------------c-----------| * B: ---d----------------e--------------f---------| * C: --x----------------y-------------z-------------| * result: ---([a,d,x])---------([b,e,y])--------([c,f,z])---| * ``` */ function withLatestFrom() { var project = undefined; for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (typeof args[args.length - 1] === 'function') { project = args.pop(); } var observables = args; return this.lift(new WithLatestFromOperator(observables, project)); } var WithLatestFromOperator = (function () { function WithLatestFromOperator(observables, project) { _classCallCheck(this, WithLatestFromOperator); this.observables = observables; this.project = project; } WithLatestFromOperator.prototype.call = function call(subscriber) { return new WithLatestFromSubscriber(subscriber, this.observables, this.project); }; return WithLatestFromOperator; })(); var WithLatestFromSubscriber = (function (_OuterSubscriber) { _inherits(WithLatestFromSubscriber, _OuterSubscriber); function WithLatestFromSubscriber(destination, observables, project) { _classCallCheck(this, WithLatestFromSubscriber); _OuterSubscriber.call(this, destination); this.observables = observables; this.project = project; this.toRespond = []; var len = observables.length; this.values = new Array(len); for (var i = 0; i < len; i++) { this.toRespond.push(i); } for (var i = 0; i < len; i++) { var observable = observables[i]; this.add(_utilSubscribeToResult2['default'](this, observable, observable, i)); } } //# sourceMappingURL=withLatestFrom.js.map WithLatestFromSubscriber.prototype.notifyNext = function notifyNext(observable, value, observableIndex, index) { this.values[observableIndex] = value; var toRespond = this.toRespond; if (toRespond.length > 0) { var found = toRespond.indexOf(observableIndex); if (found !== -1) { toRespond.splice(found, 1); } } }; WithLatestFromSubscriber.prototype.notifyComplete = function notifyComplete() { // noop }; WithLatestFromSubscriber.prototype._next = function _next(value) { if (this.toRespond.length === 0) { var values = this.values; var destination = this.destination; var project = this.project; var args = [value].concat(values); if (project) { var result = _utilTryCatch2['default'](this.project).apply(this, args); Iif (result === _utilErrorObject.errorObject) { destination.error(result.e); } else { destination.next(result); } } else { destination.next(args); } } }; return WithLatestFromSubscriber; })(_OuterSubscriber3['default']); module.exports = exports['default']; //# sourceMappingURL=withLatestFrom.js.map |