rxjs-rails 2.2.27 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -3
- data/lib/rxjs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
- data/vendor/assets/javascripts/rx.all.compat.js +1545 -1441
- data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
- data/vendor/assets/javascripts/rx.all.js +1545 -1441
- data/vendor/assets/javascripts/rx.all.min.js +3 -3
- data/vendor/assets/javascripts/rx.async.compat.js +149 -152
- data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.async.js +140 -143
- data/vendor/assets/javascripts/rx.async.min.js +1 -1
- data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
- data/vendor/assets/javascripts/rx.binding.js +18 -18
- data/vendor/assets/javascripts/rx.binding.min.js +1 -1
- data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
- data/vendor/assets/javascripts/rx.compat.js +490 -339
- data/vendor/assets/javascripts/rx.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.core.compat.js +109 -141
- data/vendor/assets/javascripts/rx.core.compat.min.js +1 -1
- data/vendor/assets/javascripts/rx.core.js +109 -141
- data/vendor/assets/javascripts/rx.core.min.js +1 -1
- data/vendor/assets/javascripts/rx.experimental.js +129 -136
- data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
- data/vendor/assets/javascripts/rx.joinpatterns.js +59 -59
- data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
- data/vendor/assets/javascripts/rx.js +490 -339
- data/vendor/assets/javascripts/rx.lite.compat.js +1099 -954
- data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
- data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
- data/vendor/assets/javascripts/rx.lite.js +1099 -954
- data/vendor/assets/javascripts/rx.lite.min.js +2 -2
- data/vendor/assets/javascripts/rx.min.js +2 -2
- data/vendor/assets/javascripts/rx.testing.min.js +1 -1
- data/vendor/assets/javascripts/rx.time.js +715 -747
- data/vendor/assets/javascripts/rx.time.min.js +1 -1
- data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
- metadata +11 -10
@@ -50,8 +50,11 @@
|
|
50
50
|
Subject = Rx.Subject,
|
51
51
|
addRef = Rx.internals.addRef,
|
52
52
|
normalizeTime = Rx.Scheduler.normalize,
|
53
|
-
|
54
|
-
|
53
|
+
helpers = Rx.helpers,
|
54
|
+
isPromise = helpers.isPromise,
|
55
|
+
isScheduler = helpers.isScheduler,
|
56
|
+
observableFromPromise = Observable.fromPromise,
|
57
|
+
notDefined = helpers.notDefined;
|
55
58
|
|
56
59
|
function observableTimerDate(dueTime, scheduler) {
|
57
60
|
return new AnonymousObservable(function (observer) {
|
@@ -62,24 +65,24 @@
|
|
62
65
|
});
|
63
66
|
}
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
68
|
+
function observableTimerDateAndPeriod(dueTime, period, scheduler) {
|
69
|
+
var p = normalizeTime(period);
|
70
|
+
return new AnonymousObservable(function (observer) {
|
71
|
+
var count = 0, d = dueTime;
|
72
|
+
return scheduler.scheduleRecursiveWithAbsolute(d, function (self) {
|
73
|
+
var now;
|
74
|
+
if (p > 0) {
|
75
|
+
now = scheduler.now();
|
76
|
+
d = d + p;
|
77
|
+
if (d <= now) {
|
78
|
+
d = now + p;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
observer.onNext(count++);
|
82
|
+
self(d);
|
83
|
+
});
|
84
|
+
});
|
85
|
+
}
|
83
86
|
|
84
87
|
function observableTimerTimeSpan(dueTime, scheduler) {
|
85
88
|
var d = normalizeTime(dueTime);
|
@@ -91,357 +94,343 @@
|
|
91
94
|
});
|
92
95
|
}
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
});
|
101
|
-
});
|
102
|
-
}
|
103
|
-
return observableDefer(function () {
|
104
|
-
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
97
|
+
function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
|
98
|
+
if (dueTime === period) {
|
99
|
+
return new AnonymousObservable(function (observer) {
|
100
|
+
return scheduler.schedulePeriodicWithState(0, period, function (count) {
|
101
|
+
observer.onNext(count);
|
102
|
+
return count + 1;
|
105
103
|
});
|
104
|
+
});
|
106
105
|
}
|
106
|
+
return observableDefer(function () {
|
107
|
+
return observableTimerDateAndPeriod(scheduler.now() + dueTime, period, scheduler);
|
108
|
+
});
|
109
|
+
}
|
107
110
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
};
|
111
|
+
/**
|
112
|
+
* Returns an observable sequence that produces a value after each period.
|
113
|
+
*
|
114
|
+
* @example
|
115
|
+
* 1 - res = Rx.Observable.interval(1000);
|
116
|
+
* 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout);
|
117
|
+
*
|
118
|
+
* @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds).
|
119
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used.
|
120
|
+
* @returns {Observable} An observable sequence that produces a value after each period.
|
121
|
+
*/
|
122
|
+
var observableinterval = Observable.interval = function (period, scheduler) {
|
123
|
+
return observableTimerTimeSpanAndPeriod(period, period, isScheduler(scheduler) ? scheduler : timeoutScheduler);
|
124
|
+
};
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
};
|
126
|
+
/**
|
127
|
+
* Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
|
128
|
+
*
|
129
|
+
* @example
|
130
|
+
* 1 - res = Rx.Observable.timer(new Date());
|
131
|
+
* 2 - res = Rx.Observable.timer(new Date(), 1000);
|
132
|
+
* 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
|
133
|
+
* 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
|
134
|
+
*
|
135
|
+
* 5 - res = Rx.Observable.timer(5000);
|
136
|
+
* 6 - res = Rx.Observable.timer(5000, 1000);
|
137
|
+
* 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
|
138
|
+
* 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
|
139
|
+
*
|
140
|
+
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) at which to produce the first value.
|
141
|
+
* @param {Mixed} [periodOrScheduler] Period to produce subsequent values (specified as an integer denoting milliseconds), or the scheduler to run the timer on. If not specified, the resulting timer is not recurring.
|
142
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
|
143
|
+
* @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period.
|
144
|
+
*/
|
145
|
+
var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
|
146
|
+
var period;
|
147
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
148
|
+
if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
|
149
|
+
period = periodOrScheduler;
|
150
|
+
} else if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'object') {
|
151
|
+
scheduler = periodOrScheduler;
|
152
|
+
}
|
153
|
+
if (dueTime instanceof Date && notDefined(period)) {
|
154
|
+
return observableTimerDate(dueTime.getTime(), scheduler);
|
155
|
+
}
|
156
|
+
if (dueTime instanceof Date && period !== undefined) {
|
157
|
+
period = periodOrScheduler;
|
158
|
+
return observableTimerDateAndPeriod(dueTime.getTime(), period, scheduler);
|
159
|
+
}
|
160
|
+
return notDefined(period) ?
|
161
|
+
observableTimerTimeSpan(dueTime, scheduler) :
|
162
|
+
observableTimerTimeSpanAndPeriod(dueTime, period, scheduler);
|
163
|
+
};
|
163
164
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
165
|
+
function observableDelayTimeSpan(source, dueTime, scheduler) {
|
166
|
+
return new AnonymousObservable(function (observer) {
|
167
|
+
var active = false,
|
168
|
+
cancelable = new SerialDisposable(),
|
169
|
+
exception = null,
|
170
|
+
q = [],
|
171
|
+
running = false,
|
172
|
+
subscription;
|
173
|
+
subscription = source.materialize().timestamp(scheduler).subscribe(function (notification) {
|
174
|
+
var d, shouldRun;
|
175
|
+
if (notification.value.kind === 'E') {
|
176
|
+
q = [];
|
177
|
+
q.push(notification);
|
178
|
+
exception = notification.value.exception;
|
179
|
+
shouldRun = !running;
|
180
|
+
} else {
|
181
|
+
q.push({ value: notification.value, timestamp: notification.timestamp + dueTime });
|
182
|
+
shouldRun = !active;
|
183
|
+
active = true;
|
184
|
+
}
|
185
|
+
if (shouldRun) {
|
186
|
+
if (exception !== null) {
|
187
|
+
observer.onError(exception);
|
188
|
+
} else {
|
189
|
+
d = new SingleAssignmentDisposable();
|
190
|
+
cancelable.setDisposable(d);
|
191
|
+
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
192
|
+
var e, recurseDueTime, result, shouldRecurse;
|
193
|
+
if (exception !== null) {
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
running = true;
|
197
|
+
do {
|
198
|
+
result = null;
|
199
|
+
if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
200
|
+
result = q.shift().value;
|
184
201
|
}
|
185
|
-
if (
|
186
|
-
|
187
|
-
observer.onError(exception);
|
188
|
-
} else {
|
189
|
-
d = new SingleAssignmentDisposable();
|
190
|
-
cancelable.setDisposable(d);
|
191
|
-
d.setDisposable(scheduler.scheduleRecursiveWithRelative(dueTime, function (self) {
|
192
|
-
var e, recurseDueTime, result, shouldRecurse;
|
193
|
-
if (exception !== null) {
|
194
|
-
return;
|
195
|
-
}
|
196
|
-
running = true;
|
197
|
-
do {
|
198
|
-
result = null;
|
199
|
-
if (q.length > 0 && q[0].timestamp - scheduler.now() <= 0) {
|
200
|
-
result = q.shift().value;
|
201
|
-
}
|
202
|
-
if (result !== null) {
|
203
|
-
result.accept(observer);
|
204
|
-
}
|
205
|
-
} while (result !== null);
|
206
|
-
shouldRecurse = false;
|
207
|
-
recurseDueTime = 0;
|
208
|
-
if (q.length > 0) {
|
209
|
-
shouldRecurse = true;
|
210
|
-
recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
211
|
-
} else {
|
212
|
-
active = false;
|
213
|
-
}
|
214
|
-
e = exception;
|
215
|
-
running = false;
|
216
|
-
if (e !== null) {
|
217
|
-
observer.onError(e);
|
218
|
-
} else if (shouldRecurse) {
|
219
|
-
self(recurseDueTime);
|
220
|
-
}
|
221
|
-
}));
|
222
|
-
}
|
202
|
+
if (result !== null) {
|
203
|
+
result.accept(observer);
|
223
204
|
}
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
205
|
+
} while (result !== null);
|
206
|
+
shouldRecurse = false;
|
207
|
+
recurseDueTime = 0;
|
208
|
+
if (q.length > 0) {
|
209
|
+
shouldRecurse = true;
|
210
|
+
recurseDueTime = Math.max(0, q[0].timestamp - scheduler.now());
|
211
|
+
} else {
|
212
|
+
active = false;
|
213
|
+
}
|
214
|
+
e = exception;
|
215
|
+
running = false;
|
216
|
+
if (e !== null) {
|
217
|
+
observer.onError(e);
|
218
|
+
} else if (shouldRecurse) {
|
219
|
+
self(recurseDueTime);
|
220
|
+
}
|
221
|
+
}));
|
222
|
+
}
|
223
|
+
}
|
224
|
+
});
|
225
|
+
return new CompositeDisposable(subscription, cancelable);
|
226
|
+
});
|
227
|
+
}
|
228
228
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
});
|
235
|
-
}
|
229
|
+
function observableDelayDate(source, dueTime, scheduler) {
|
230
|
+
return observableDefer(function () {
|
231
|
+
return observableDelayTimeSpan(source, dueTime - scheduler.now(), scheduler);
|
232
|
+
});
|
233
|
+
}
|
236
234
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
235
|
+
/**
|
236
|
+
* Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
|
237
|
+
*
|
238
|
+
* @example
|
239
|
+
* 1 - res = Rx.Observable.delay(new Date());
|
240
|
+
* 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout);
|
241
|
+
*
|
242
|
+
* 3 - res = Rx.Observable.delay(5000);
|
243
|
+
* 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
|
244
|
+
* @memberOf Observable#
|
245
|
+
* @param {Number} dueTime Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence.
|
246
|
+
* @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
|
247
|
+
* @returns {Observable} Time-shifted sequence.
|
248
|
+
*/
|
249
|
+
observableProto.delay = function (dueTime, scheduler) {
|
250
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
251
|
+
return dueTime instanceof Date ?
|
252
|
+
observableDelayDate(this, dueTime.getTime(), scheduler) :
|
253
|
+
observableDelayTimeSpan(this, dueTime, scheduler);
|
254
|
+
};
|
257
255
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
};
|
256
|
+
/**
|
257
|
+
* Ignores values from an observable sequence which are followed by another value before dueTime.
|
258
|
+
*
|
259
|
+
* @example
|
260
|
+
* 1 - res = source.throttle(5000); // 5 seconds
|
261
|
+
* 2 - res = source.throttle(5000, scheduler);
|
262
|
+
*
|
263
|
+
* @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
|
264
|
+
* @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
|
265
|
+
* @returns {Observable} The throttled sequence.
|
266
|
+
*/
|
267
|
+
observableProto.throttle = function (dueTime, scheduler) {
|
268
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
269
|
+
return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
|
270
|
+
};
|
274
271
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
272
|
+
/**
|
273
|
+
* Projects each element of an observable sequence into zero or more windows which are produced based on timing information.
|
274
|
+
*
|
275
|
+
* @example
|
276
|
+
* 1 - res = xs.windowWithTime(1000, scheduler); // non-overlapping segments of 1 second
|
277
|
+
* 2 - res = xs.windowWithTime(1000, 500 , scheduler); // segments of 1 second with time shift 0.5 seconds
|
278
|
+
*
|
279
|
+
* @param {Number} timeSpan Length of each window (specified as an integer denoting milliseconds).
|
280
|
+
* @param {Mixed} [timeShiftOrScheduler] Interval between creation of consecutive windows (specified as an integer denoting milliseconds), or an optional scheduler parameter. If not specified, the time shift corresponds to the timeSpan parameter, resulting in non-overlapping adjacent windows.
|
281
|
+
* @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
|
282
|
+
* @returns {Observable} An observable sequence of windows.
|
283
|
+
*/
|
284
|
+
observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
|
285
|
+
var source = this, timeShift;
|
286
|
+
|
287
|
+
notDefined(timeShiftOrScheduler) && (timeShift = timeSpan);
|
288
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
289
|
+
if (typeof timeShiftOrScheduler === 'number') {
|
290
|
+
timeShift = timeShiftOrScheduler;
|
291
|
+
} else if (typeof timeShiftOrScheduler === 'object') {
|
292
|
+
timeShift = timeSpan;
|
293
|
+
scheduler = timeShiftOrScheduler;
|
294
|
+
}
|
295
|
+
return new AnonymousObservable(function (observer) {
|
296
|
+
var groupDisposable,
|
297
|
+
nextShift = timeShift,
|
298
|
+
nextSpan = timeSpan,
|
299
|
+
q = [],
|
300
|
+
refCountDisposable,
|
301
|
+
timerD = new SerialDisposable(),
|
302
|
+
totalTime = 0;
|
303
|
+
groupDisposable = new CompositeDisposable(timerD),
|
304
|
+
refCountDisposable = new RefCountDisposable(groupDisposable);
|
305
|
+
|
306
|
+
|
307
|
+
q.push(new Subject());
|
308
|
+
observer.onNext(addRef(q[0], refCountDisposable));
|
309
|
+
createTimer();
|
310
|
+
groupDisposable.add(source.subscribe(function (x) {
|
311
|
+
var i, len;
|
312
|
+
for (i = 0, len = q.length; i < len; i++) {
|
313
|
+
q[i].onNext(x);
|
291
314
|
}
|
292
|
-
|
293
|
-
|
315
|
+
}, function (e) {
|
316
|
+
var i, len;
|
317
|
+
for (i = 0, len = q.length; i < len; i++) {
|
318
|
+
q[i].onError(e);
|
294
319
|
}
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
320
|
+
observer.onError(e);
|
321
|
+
}, function () {
|
322
|
+
var i, len;
|
323
|
+
for (i = 0, len = q.length; i < len; i++) {
|
324
|
+
q[i].onCompleted();
|
300
325
|
}
|
301
|
-
|
302
|
-
|
303
|
-
nextShift = timeShift,
|
304
|
-
nextSpan = timeSpan,
|
305
|
-
q = [],
|
306
|
-
refCountDisposable,
|
307
|
-
timerD = new SerialDisposable(),
|
308
|
-
totalTime = 0;
|
309
|
-
groupDisposable = new CompositeDisposable(timerD),
|
310
|
-
refCountDisposable = new RefCountDisposable(groupDisposable);
|
326
|
+
observer.onCompleted();
|
327
|
+
}));
|
311
328
|
|
312
|
-
|
313
|
-
var m = new SingleAssignmentDisposable(),
|
314
|
-
isSpan = false,
|
315
|
-
isShift = false;
|
316
|
-
timerD.setDisposable(m);
|
317
|
-
if (nextSpan === nextShift) {
|
318
|
-
isSpan = true;
|
319
|
-
isShift = true;
|
320
|
-
} else if (nextSpan < nextShift) {
|
321
|
-
isSpan = true;
|
322
|
-
} else {
|
323
|
-
isShift = true;
|
324
|
-
}
|
325
|
-
var newTotalTime = isSpan ? nextSpan : nextShift,
|
326
|
-
ts = newTotalTime - totalTime;
|
327
|
-
totalTime = newTotalTime;
|
328
|
-
if (isSpan) {
|
329
|
-
nextSpan += timeShift;
|
330
|
-
}
|
331
|
-
if (isShift) {
|
332
|
-
nextShift += timeShift;
|
333
|
-
}
|
334
|
-
m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
|
335
|
-
var s;
|
336
|
-
if (isShift) {
|
337
|
-
s = new Subject();
|
338
|
-
q.push(s);
|
339
|
-
observer.onNext(addRef(s, refCountDisposable));
|
340
|
-
}
|
341
|
-
if (isSpan) {
|
342
|
-
s = q.shift();
|
343
|
-
s.onCompleted();
|
344
|
-
}
|
345
|
-
createTimer();
|
346
|
-
}));
|
347
|
-
};
|
348
|
-
q.push(new Subject());
|
349
|
-
observer.onNext(addRef(q[0], refCountDisposable));
|
350
|
-
createTimer();
|
351
|
-
groupDisposable.add(source.subscribe(function (x) {
|
352
|
-
var i, s;
|
353
|
-
for (i = 0; i < q.length; i++) {
|
354
|
-
s = q[i];
|
355
|
-
s.onNext(x);
|
356
|
-
}
|
357
|
-
}, function (e) {
|
358
|
-
var i, s;
|
359
|
-
for (i = 0; i < q.length; i++) {
|
360
|
-
s = q[i];
|
361
|
-
s.onError(e);
|
362
|
-
}
|
363
|
-
observer.onError(e);
|
364
|
-
}, function () {
|
365
|
-
var i, s;
|
366
|
-
for (i = 0; i < q.length; i++) {
|
367
|
-
s = q[i];
|
368
|
-
s.onCompleted();
|
369
|
-
}
|
370
|
-
observer.onCompleted();
|
371
|
-
}));
|
372
|
-
return refCountDisposable;
|
373
|
-
});
|
374
|
-
};
|
329
|
+
return refCountDisposable;
|
375
330
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
var
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
windowId = 0;
|
399
|
-
groupDisposable = new CompositeDisposable(timerD);
|
400
|
-
refCountDisposable = new RefCountDisposable(groupDisposable);
|
401
|
-
createTimer = function (id) {
|
402
|
-
var m = new SingleAssignmentDisposable();
|
403
|
-
timerD.setDisposable(m);
|
404
|
-
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
405
|
-
var newId;
|
406
|
-
if (id !== windowId) {
|
407
|
-
return;
|
408
|
-
}
|
409
|
-
n = 0;
|
410
|
-
newId = ++windowId;
|
411
|
-
s.onCompleted();
|
412
|
-
s = new Subject();
|
413
|
-
observer.onNext(addRef(s, refCountDisposable));
|
414
|
-
createTimer(newId);
|
415
|
-
}));
|
416
|
-
};
|
331
|
+
function createTimer () {
|
332
|
+
var m = new SingleAssignmentDisposable(), isSpan = false, isShift = false;
|
333
|
+
timerD.setDisposable(m);
|
334
|
+
|
335
|
+
if (nextSpan === nextShift) {
|
336
|
+
isSpan = true;
|
337
|
+
isShift = true;
|
338
|
+
} else if (nextSpan < nextShift) {
|
339
|
+
isSpan = true;
|
340
|
+
} else {
|
341
|
+
isShift = true;
|
342
|
+
}
|
343
|
+
|
344
|
+
var newTotalTime = isSpan ? nextSpan : nextShift,
|
345
|
+
ts = newTotalTime - totalTime;
|
346
|
+
totalTime = newTotalTime;
|
347
|
+
isSpan && (nextSpan += timeShift);
|
348
|
+
isShift && (nextShift += timeShift);
|
349
|
+
|
350
|
+
m.setDisposable(scheduler.scheduleWithRelative(ts, function () {
|
351
|
+
var s;
|
352
|
+
if (isShift) {
|
417
353
|
s = new Subject();
|
354
|
+
q.push(s);
|
418
355
|
observer.onNext(addRef(s, refCountDisposable));
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
356
|
+
}
|
357
|
+
if (isSpan) {
|
358
|
+
s = q.shift();
|
359
|
+
s.onCompleted();
|
360
|
+
}
|
361
|
+
createTimer();
|
362
|
+
}));
|
363
|
+
}
|
364
|
+
});
|
365
|
+
};
|
366
|
+
|
367
|
+
/**
|
368
|
+
* Projects each element of an observable sequence into a window that is completed when either it's full or a given amount of time has elapsed.
|
369
|
+
* @example
|
370
|
+
* 1 - res = source.windowWithTimeOrCount(5000, 50); // 5s or 50 items
|
371
|
+
* 2 - res = source.windowWithTimeOrCount(5000, 50, scheduler); //5s or 50 items
|
372
|
+
*
|
373
|
+
* @memberOf Observable#
|
374
|
+
* @param {Number} timeSpan Maximum time length of a window.
|
375
|
+
* @param {Number} count Maximum element count of a window.
|
376
|
+
* @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
|
377
|
+
* @returns {Observable} An observable sequence of windows.
|
378
|
+
*/
|
379
|
+
observableProto.windowWithTimeOrCount = function (timeSpan, count, scheduler) {
|
380
|
+
var source = this;
|
381
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
382
|
+
return new AnonymousObservable(function (observer) {
|
383
|
+
var createTimer,
|
384
|
+
groupDisposable,
|
385
|
+
n = 0,
|
386
|
+
refCountDisposable,
|
387
|
+
s = new Subject()
|
388
|
+
timerD = new SerialDisposable(),
|
389
|
+
windowId = 0;
|
390
|
+
groupDisposable = new CompositeDisposable(timerD);
|
391
|
+
refCountDisposable = new RefCountDisposable(groupDisposable);
|
392
|
+
|
393
|
+
observer.onNext(addRef(s, refCountDisposable));
|
394
|
+
createTimer(0);
|
395
|
+
groupDisposable.add(source.subscribe(function (x) {
|
396
|
+
var newId = 0, newWindow = false;
|
397
|
+
s.onNext(x);
|
398
|
+
n++;
|
399
|
+
if (n === count) {
|
400
|
+
newWindow = true;
|
401
|
+
n = 0;
|
402
|
+
newId = ++windowId;
|
403
|
+
s.onCompleted();
|
404
|
+
s = new Subject();
|
405
|
+
observer.onNext(addRef(s, refCountDisposable));
|
406
|
+
}
|
407
|
+
newWindow && createTimer(newId);
|
408
|
+
}, function (e) {
|
409
|
+
s.onError(e);
|
410
|
+
observer.onError(e);
|
411
|
+
}, function () {
|
412
|
+
s.onCompleted();
|
413
|
+
observer.onCompleted();
|
414
|
+
}));
|
415
|
+
|
416
|
+
return refCountDisposable;
|
417
|
+
|
418
|
+
function createTimer(id) {
|
419
|
+
var m = new SingleAssignmentDisposable();
|
420
|
+
timerD.setDisposable(m);
|
421
|
+
m.setDisposable(scheduler.scheduleWithRelative(timeSpan, function () {
|
422
|
+
var newId;
|
423
|
+
if (id !== windowId) { return; }
|
424
|
+
n = 0;
|
425
|
+
newId = ++windowId;
|
426
|
+
s.onCompleted();
|
427
|
+
s = new Subject();
|
428
|
+
observer.onNext(addRef(s, refCountDisposable));
|
429
|
+
createTimer(newId);
|
430
|
+
}));
|
431
|
+
}
|
432
|
+
});
|
433
|
+
};
|
445
434
|
|
446
435
|
/**
|
447
436
|
* Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.
|
@@ -477,98 +466,89 @@
|
|
477
466
|
});
|
478
467
|
};
|
479
468
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
});
|
503
|
-
});
|
504
|
-
};
|
469
|
+
/**
|
470
|
+
* Records the time interval between consecutive values in an observable sequence.
|
471
|
+
*
|
472
|
+
* @example
|
473
|
+
* 1 - res = source.timeInterval();
|
474
|
+
* 2 - res = source.timeInterval(Rx.Scheduler.timeout);
|
475
|
+
*
|
476
|
+
* @param [scheduler] Scheduler used to compute time intervals. If not specified, the timeout scheduler is used.
|
477
|
+
* @returns {Observable} An observable sequence with time interval information on values.
|
478
|
+
*/
|
479
|
+
observableProto.timeInterval = function (scheduler) {
|
480
|
+
var source = this;
|
481
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
482
|
+
return observableDefer(function () {
|
483
|
+
var last = scheduler.now();
|
484
|
+
return source.map(function (x) {
|
485
|
+
var now = scheduler.now(), span = now - last;
|
486
|
+
last = now;
|
487
|
+
return { value: x, interval: span };
|
488
|
+
});
|
489
|
+
});
|
490
|
+
};
|
505
491
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
};
|
523
|
-
});
|
524
|
-
};
|
492
|
+
/**
|
493
|
+
* Records the timestamp for each value in an observable sequence.
|
494
|
+
*
|
495
|
+
* @example
|
496
|
+
* 1 - res = source.timestamp(); // produces { value: x, timestamp: ts }
|
497
|
+
* 2 - res = source.timestamp(Rx.Scheduler.timeout);
|
498
|
+
*
|
499
|
+
* @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the timeout scheduler is used.
|
500
|
+
* @returns {Observable} An observable sequence with timestamp information on values.
|
501
|
+
*/
|
502
|
+
observableProto.timestamp = function (scheduler) {
|
503
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
504
|
+
return this.map(function (x) {
|
505
|
+
return { value: x, timestamp: scheduler.now() };
|
506
|
+
});
|
507
|
+
};
|
525
508
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
509
|
+
function sampleObservable(source, sampler) {
|
510
|
+
|
511
|
+
return new AnonymousObservable(function (observer) {
|
512
|
+
var atEnd, value, hasValue;
|
530
513
|
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
}
|
539
|
-
}
|
514
|
+
function sampleSubscribe() {
|
515
|
+
if (hasValue) {
|
516
|
+
hasValue = false;
|
517
|
+
observer.onNext(value);
|
518
|
+
}
|
519
|
+
atEnd && observer.onCompleted();
|
520
|
+
}
|
540
521
|
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
522
|
+
return new CompositeDisposable(
|
523
|
+
source.subscribe(function (newValue) {
|
524
|
+
hasValue = true;
|
525
|
+
value = newValue;
|
526
|
+
}, observer.onError.bind(observer), function () {
|
527
|
+
atEnd = true;
|
528
|
+
}),
|
529
|
+
sampler.subscribe(sampleSubscribe, observer.onError.bind(observer), sampleSubscribe)
|
530
|
+
);
|
531
|
+
});
|
532
|
+
}
|
552
533
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
};
|
534
|
+
/**
|
535
|
+
* Samples the observable sequence at each interval.
|
536
|
+
*
|
537
|
+
* @example
|
538
|
+
* 1 - res = source.sample(sampleObservable); // Sampler tick sequence
|
539
|
+
* 2 - res = source.sample(5000); // 5 seconds
|
540
|
+
* 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds
|
541
|
+
*
|
542
|
+
* @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable.
|
543
|
+
* @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
|
544
|
+
* @returns {Observable} Sampled observable sequence.
|
545
|
+
*/
|
546
|
+
observableProto.sample = function (intervalOrSampler, scheduler) {
|
547
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
548
|
+
return typeof intervalOrSampler === 'number' ?
|
549
|
+
sampleObservable(this, observableinterval(intervalOrSampler, scheduler)) :
|
550
|
+
sampleObservable(this, intervalOrSampler);
|
551
|
+
};
|
572
552
|
|
573
553
|
/**
|
574
554
|
* Returns the source observable sequence or the other observable sequence if dueTime elapses.
|
@@ -588,7 +568,7 @@
|
|
588
568
|
*/
|
589
569
|
observableProto.timeout = function (dueTime, other, scheduler) {
|
590
570
|
other || (other = observableThrow(new Error('Timeout')));
|
591
|
-
scheduler || (scheduler = timeoutScheduler);
|
571
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
592
572
|
|
593
573
|
var source = this, schedulerMethod = dueTime instanceof Date ?
|
594
574
|
'scheduleWithAbsolute' :
|
@@ -636,131 +616,128 @@
|
|
636
616
|
});
|
637
617
|
};
|
638
618
|
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
};
|
619
|
+
/**
|
620
|
+
* Generates an observable sequence by iterating a state from an initial state until the condition fails.
|
621
|
+
*
|
622
|
+
* @example
|
623
|
+
* res = source.generateWithAbsoluteTime(0,
|
624
|
+
* function (x) { return return true; },
|
625
|
+
* function (x) { return x + 1; },
|
626
|
+
* function (x) { return x; },
|
627
|
+
* function (x) { return new Date(); }
|
628
|
+
* });
|
629
|
+
*
|
630
|
+
* @param {Mixed} initialState Initial state.
|
631
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
632
|
+
* @param {Function} iterate Iteration step function.
|
633
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
634
|
+
* @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning Date values.
|
635
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
|
636
|
+
* @returns {Observable} The generated sequence.
|
637
|
+
*/
|
638
|
+
Observable.generateWithAbsoluteTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
639
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
640
|
+
return new AnonymousObservable(function (observer) {
|
641
|
+
var first = true,
|
642
|
+
hasResult = false,
|
643
|
+
result,
|
644
|
+
state = initialState,
|
645
|
+
time;
|
646
|
+
return scheduler.scheduleRecursiveWithAbsolute(scheduler.now(), function (self) {
|
647
|
+
hasResult && observer.onNext(result);
|
648
|
+
|
649
|
+
try {
|
650
|
+
if (first) {
|
651
|
+
first = false;
|
652
|
+
} else {
|
653
|
+
state = iterate(state);
|
654
|
+
}
|
655
|
+
hasResult = condition(state);
|
656
|
+
if (hasResult) {
|
657
|
+
result = resultSelector(state);
|
658
|
+
time = timeSelector(state);
|
659
|
+
}
|
660
|
+
} catch (e) {
|
661
|
+
observer.onError(e);
|
662
|
+
return;
|
663
|
+
}
|
664
|
+
if (hasResult) {
|
665
|
+
self(time);
|
666
|
+
} else {
|
667
|
+
observer.onCompleted();
|
668
|
+
}
|
669
|
+
});
|
670
|
+
});
|
671
|
+
};
|
693
672
|
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
observer.onNext(result);
|
724
|
-
}
|
725
|
-
try {
|
726
|
-
if (first) {
|
727
|
-
first = false;
|
728
|
-
} else {
|
729
|
-
state = iterate(state);
|
730
|
-
}
|
731
|
-
hasResult = condition(state);
|
732
|
-
if (hasResult) {
|
733
|
-
result = resultSelector(state);
|
734
|
-
time = timeSelector(state);
|
735
|
-
}
|
736
|
-
} catch (e) {
|
737
|
-
observer.onError(e);
|
738
|
-
return;
|
739
|
-
}
|
740
|
-
if (hasResult) {
|
741
|
-
self(time);
|
742
|
-
} else {
|
743
|
-
observer.onCompleted();
|
744
|
-
}
|
745
|
-
});
|
746
|
-
});
|
747
|
-
};
|
673
|
+
/**
|
674
|
+
* Generates an observable sequence by iterating a state from an initial state until the condition fails.
|
675
|
+
*
|
676
|
+
* @example
|
677
|
+
* res = source.generateWithRelativeTime(0,
|
678
|
+
* function (x) { return return true; },
|
679
|
+
* function (x) { return x + 1; },
|
680
|
+
* function (x) { return x; },
|
681
|
+
* function (x) { return 500; }
|
682
|
+
* );
|
683
|
+
*
|
684
|
+
* @param {Mixed} initialState Initial state.
|
685
|
+
* @param {Function} condition Condition to terminate generation (upon returning false).
|
686
|
+
* @param {Function} iterate Iteration step function.
|
687
|
+
* @param {Function} resultSelector Selector function for results produced in the sequence.
|
688
|
+
* @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning integer values denoting milliseconds.
|
689
|
+
* @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
|
690
|
+
* @returns {Observable} The generated sequence.
|
691
|
+
*/
|
692
|
+
Observable.generateWithRelativeTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
|
693
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
694
|
+
return new AnonymousObservable(function (observer) {
|
695
|
+
var first = true,
|
696
|
+
hasResult = false,
|
697
|
+
result,
|
698
|
+
state = initialState,
|
699
|
+
time;
|
700
|
+
return scheduler.scheduleRecursiveWithRelative(0, function (self) {
|
701
|
+
hasResult && observer.onNext(result);
|
748
702
|
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
703
|
+
try {
|
704
|
+
if (first) {
|
705
|
+
first = false;
|
706
|
+
} else {
|
707
|
+
state = iterate(state);
|
708
|
+
}
|
709
|
+
hasResult = condition(state);
|
710
|
+
if (hasResult) {
|
711
|
+
result = resultSelector(state);
|
712
|
+
time = timeSelector(state);
|
713
|
+
}
|
714
|
+
} catch (e) {
|
715
|
+
observer.onError(e);
|
716
|
+
return;
|
717
|
+
}
|
718
|
+
if (hasResult) {
|
719
|
+
self(time);
|
720
|
+
} else {
|
721
|
+
observer.onCompleted();
|
722
|
+
}
|
723
|
+
});
|
724
|
+
});
|
725
|
+
};
|
726
|
+
|
727
|
+
/**
|
728
|
+
* Time shifts the observable sequence by delaying the subscription.
|
729
|
+
*
|
730
|
+
* @example
|
731
|
+
* 1 - res = source.delaySubscription(5000); // 5s
|
732
|
+
* 2 - res = source.delaySubscription(5000, Rx.Scheduler.timeout); // 5 seconds
|
733
|
+
*
|
734
|
+
* @param {Number} dueTime Absolute or relative time to perform the subscription at.
|
735
|
+
* @param {Scheduler} [scheduler] Scheduler to run the subscription delay timer on. If not specified, the timeout scheduler is used.
|
736
|
+
* @returns {Observable} Time-shifted sequence.
|
737
|
+
*/
|
738
|
+
observableProto.delaySubscription = function (dueTime, scheduler) {
|
739
|
+
return this.delayWithSelector(observableTimer(dueTime, isScheduler(scheduler) ? scheduler : timeoutScheduler), observableEmpty);
|
740
|
+
};
|
764
741
|
|
765
742
|
/**
|
766
743
|
* Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.
|
@@ -906,96 +883,96 @@
|
|
906
883
|
});
|
907
884
|
};
|
908
885
|
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
886
|
+
/**
|
887
|
+
* Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
|
888
|
+
*
|
889
|
+
* @example
|
890
|
+
* 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
|
891
|
+
*
|
892
|
+
* @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
|
893
|
+
* @returns {Observable} The throttled sequence.
|
894
|
+
*/
|
895
|
+
observableProto.throttleWithSelector = function (throttleDurationSelector) {
|
896
|
+
var source = this;
|
897
|
+
return new AnonymousObservable(function (observer) {
|
898
|
+
var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
|
899
|
+
var throttle;
|
900
|
+
try {
|
901
|
+
throttle = throttleDurationSelector(x);
|
902
|
+
} catch (e) {
|
903
|
+
observer.onError(e);
|
904
|
+
return;
|
905
|
+
}
|
906
|
+
hasValue = true;
|
907
|
+
value = x;
|
908
|
+
id++;
|
909
|
+
var currentid = id, d = new SingleAssignmentDisposable();
|
910
|
+
cancelable.setDisposable(d);
|
911
|
+
d.setDisposable(throttle.subscribe(function () {
|
912
|
+
if (hasValue && id === currentid) {
|
913
|
+
observer.onNext(value);
|
914
|
+
}
|
915
|
+
hasValue = false;
|
916
|
+
d.dispose();
|
917
|
+
}, observer.onError.bind(observer), function () {
|
918
|
+
if (hasValue && id === currentid) {
|
919
|
+
observer.onNext(value);
|
920
|
+
}
|
921
|
+
hasValue = false;
|
922
|
+
d.dispose();
|
923
|
+
}));
|
924
|
+
}, function (e) {
|
925
|
+
cancelable.dispose();
|
926
|
+
observer.onError(e);
|
927
|
+
hasValue = false;
|
928
|
+
id++;
|
929
|
+
}, function () {
|
930
|
+
cancelable.dispose();
|
931
|
+
if (hasValue) {
|
932
|
+
observer.onNext(value);
|
933
|
+
}
|
934
|
+
observer.onCompleted();
|
935
|
+
hasValue = false;
|
936
|
+
id++;
|
937
|
+
});
|
938
|
+
return new CompositeDisposable(subscription, cancelable);
|
939
|
+
});
|
940
|
+
};
|
964
941
|
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
942
|
+
/**
|
943
|
+
* Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
|
944
|
+
*
|
945
|
+
* 1 - res = source.skipLastWithTime(5000);
|
946
|
+
* 2 - res = source.skipLastWithTime(5000, scheduler);
|
947
|
+
*
|
948
|
+
* @description
|
949
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
950
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
951
|
+
* result sequence. This causes elements to be delayed with duration.
|
952
|
+
* @param {Number} duration Duration for skipping elements from the end of the sequence.
|
953
|
+
* @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout
|
954
|
+
* @returns {Observable} An observable sequence with the elements skipped during the specified duration from the end of the source sequence.
|
955
|
+
*/
|
956
|
+
observableProto.skipLastWithTime = function (duration, scheduler) {
|
957
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
958
|
+
var source = this;
|
959
|
+
return new AnonymousObservable(function (observer) {
|
960
|
+
var q = [];
|
961
|
+
return source.subscribe(function (x) {
|
962
|
+
var now = scheduler.now();
|
963
|
+
q.push({ interval: now, value: x });
|
964
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
965
|
+
observer.onNext(q.shift().value);
|
966
|
+
}
|
967
|
+
}, observer.onError.bind(observer), function () {
|
968
|
+
var now = scheduler.now();
|
969
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
970
|
+
observer.onNext(q.shift().value);
|
971
|
+
}
|
972
|
+
observer.onCompleted();
|
973
|
+
});
|
974
|
+
});
|
975
|
+
};
|
999
976
|
|
1000
977
|
/**
|
1001
978
|
* Returns elements within the specified duration from the end of the observable source sequence, using the specified schedulers to run timers and to drain the collected elements.
|
@@ -1015,102 +992,93 @@
|
|
1015
992
|
return this.takeLastBufferWithTime(duration, timerScheduler).selectMany(function (xs) { return observableFromArray(xs, loopScheduler); });
|
1016
993
|
};
|
1017
994
|
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
return source.subscribe(function (x) {
|
1038
|
-
var now = scheduler.now();
|
1039
|
-
q.push({ interval: now, value: x });
|
1040
|
-
while (q.length > 0 && now - q[0].interval >= duration) {
|
1041
|
-
q.shift();
|
1042
|
-
}
|
1043
|
-
}, observer.onError.bind(observer), function () {
|
1044
|
-
var now = scheduler.now(), res = [];
|
1045
|
-
while (q.length > 0) {
|
1046
|
-
var next = q.shift();
|
1047
|
-
if (now - next.interval <= duration) {
|
1048
|
-
res.push(next.value);
|
1049
|
-
}
|
1050
|
-
}
|
1051
|
-
|
1052
|
-
observer.onNext(res);
|
1053
|
-
observer.onCompleted();
|
1054
|
-
});
|
1055
|
-
});
|
1056
|
-
};
|
995
|
+
/**
|
996
|
+
* Returns an array with the elements within the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
|
997
|
+
*
|
998
|
+
* @example
|
999
|
+
* 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
|
1000
|
+
* @description
|
1001
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
1002
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
1003
|
+
* result sequence. This causes elements to be delayed with duration.
|
1004
|
+
* @param {Number} duration Duration for taking elements from the end of the sequence.
|
1005
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
1006
|
+
* @returns {Observable} An observable sequence containing a single array with the elements taken during the specified duration from the end of the source sequence.
|
1007
|
+
*/
|
1008
|
+
observableProto.takeLastBufferWithTime = function (duration, scheduler) {
|
1009
|
+
var source = this;
|
1010
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
1011
|
+
return new AnonymousObservable(function (observer) {
|
1012
|
+
var q = [];
|
1057
1013
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
var source = this;
|
1073
|
-
scheduler || (scheduler = timeoutScheduler);
|
1074
|
-
return new AnonymousObservable(function (observer) {
|
1075
|
-
var t = scheduler.scheduleWithRelative(duration, function () {
|
1076
|
-
observer.onCompleted();
|
1077
|
-
});
|
1014
|
+
return source.subscribe(function (x) {
|
1015
|
+
var now = scheduler.now();
|
1016
|
+
q.push({ interval: now, value: x });
|
1017
|
+
while (q.length > 0 && now - q[0].interval >= duration) {
|
1018
|
+
q.shift();
|
1019
|
+
}
|
1020
|
+
}, observer.onError.bind(observer), function () {
|
1021
|
+
var now = scheduler.now(), res = [];
|
1022
|
+
while (q.length > 0) {
|
1023
|
+
var next = q.shift();
|
1024
|
+
if (now - next.interval <= duration) {
|
1025
|
+
res.push(next.value);
|
1026
|
+
}
|
1027
|
+
}
|
1078
1028
|
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1029
|
+
observer.onNext(res);
|
1030
|
+
observer.onCompleted();
|
1031
|
+
});
|
1032
|
+
});
|
1033
|
+
};
|
1082
1034
|
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
var open = false,
|
1104
|
-
t = scheduler.scheduleWithRelative(duration, function () { open = true; }),
|
1105
|
-
d = source.subscribe(function (x) {
|
1106
|
-
if (open) {
|
1107
|
-
observer.onNext(x);
|
1108
|
-
}
|
1109
|
-
}, observer.onError.bind(observer), observer.onCompleted.bind(observer));
|
1035
|
+
/**
|
1036
|
+
* Takes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
|
1037
|
+
*
|
1038
|
+
* @example
|
1039
|
+
* 1 - res = source.takeWithTime(5000, [optional scheduler]);
|
1040
|
+
* @description
|
1041
|
+
* This operator accumulates a queue with a length enough to store elements received during the initial duration window.
|
1042
|
+
* As more elements are received, elements older than the specified duration are taken from the queue and produced on the
|
1043
|
+
* result sequence. This causes elements to be delayed with duration.
|
1044
|
+
* @param {Number} duration Duration for taking elements from the start of the sequence.
|
1045
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
1046
|
+
* @returns {Observable} An observable sequence with the elements taken during the specified duration from the start of the source sequence.
|
1047
|
+
*/
|
1048
|
+
observableProto.takeWithTime = function (duration, scheduler) {
|
1049
|
+
var source = this;
|
1050
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
1051
|
+
return new AnonymousObservable(function (observer) {
|
1052
|
+
return new CompositeDisposable(scheduler.scheduleWithRelative(duration, observer.onCompleted.bind(observer)), source.subscribe(observer));
|
1053
|
+
});
|
1054
|
+
};
|
1110
1055
|
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1056
|
+
/**
|
1057
|
+
* Skips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
|
1058
|
+
*
|
1059
|
+
* @example
|
1060
|
+
* 1 - res = source.skipWithTime(5000, [optional scheduler]);
|
1061
|
+
*
|
1062
|
+
* @description
|
1063
|
+
* Specifying a zero value for duration doesn't guarantee no elements will be dropped from the start of the source sequence.
|
1064
|
+
* This is a side-effect of the asynchrony introduced by the scheduler, where the action that causes callbacks from the source sequence to be forwarded
|
1065
|
+
* may not execute immediately, despite the zero due time.
|
1066
|
+
*
|
1067
|
+
* Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the duration.
|
1068
|
+
* @param {Number} duration Duration for skipping elements from the start of the sequence.
|
1069
|
+
* @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
|
1070
|
+
* @returns {Observable} An observable sequence with the elements skipped during the specified duration from the start of the source sequence.
|
1071
|
+
*/
|
1072
|
+
observableProto.skipWithTime = function (duration, scheduler) {
|
1073
|
+
var source = this;
|
1074
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
1075
|
+
return new AnonymousObservable(function (observer) {
|
1076
|
+
var open = false;
|
1077
|
+
return new CompositeDisposable(
|
1078
|
+
scheduler.scheduleWithRelative(duration, function () { open = true; }),
|
1079
|
+
source.subscribe(function (x) { open && observer.onNext(x); }, observer.onError.bind(observer), observer.onCompleted.bind(observer)));
|
1080
|
+
});
|
1081
|
+
};
|
1114
1082
|
|
1115
1083
|
/**
|
1116
1084
|
* Skips elements from the observable source sequence until the specified start time, using the specified scheduler to run timers.
|
@@ -1124,7 +1092,7 @@
|
|
1124
1092
|
* @returns {Observable} An observable sequence with the elements skipped until the specified start time.
|
1125
1093
|
*/
|
1126
1094
|
observableProto.skipUntilWithTime = function (startTime, scheduler) {
|
1127
|
-
scheduler || (scheduler = timeoutScheduler);
|
1095
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
1128
1096
|
var source = this, schedulerMethod = startTime instanceof Date ?
|
1129
1097
|
'scheduleWithAbsolute' :
|
1130
1098
|
'scheduleWithRelative';
|
@@ -1151,7 +1119,7 @@
|
|
1151
1119
|
* @returns {Observable} An observable sequence with the elements taken until the specified end time.
|
1152
1120
|
*/
|
1153
1121
|
observableProto.takeUntilWithTime = function (endTime, scheduler) {
|
1154
|
-
scheduler || (scheduler = timeoutScheduler);
|
1122
|
+
isScheduler(scheduler) || (scheduler = timeoutScheduler);
|
1155
1123
|
var source = this, schedulerMethod = endTime instanceof Date ?
|
1156
1124
|
'scheduleWithAbsolute' :
|
1157
1125
|
'scheduleWithRelative';
|