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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -3
  3. data/lib/rxjs/rails/version.rb +1 -1
  4. data/vendor/assets/javascripts/rx.aggregates.min.js +1 -1
  5. data/vendor/assets/javascripts/rx.all.compat.js +1545 -1441
  6. data/vendor/assets/javascripts/rx.all.compat.min.js +3 -3
  7. data/vendor/assets/javascripts/rx.all.js +1545 -1441
  8. data/vendor/assets/javascripts/rx.all.min.js +3 -3
  9. data/vendor/assets/javascripts/rx.async.compat.js +149 -152
  10. data/vendor/assets/javascripts/rx.async.compat.min.js +1 -1
  11. data/vendor/assets/javascripts/rx.async.js +140 -143
  12. data/vendor/assets/javascripts/rx.async.min.js +1 -1
  13. data/vendor/assets/javascripts/rx.backpressure.min.js +1 -1
  14. data/vendor/assets/javascripts/rx.binding.js +18 -18
  15. data/vendor/assets/javascripts/rx.binding.min.js +1 -1
  16. data/vendor/assets/javascripts/rx.coincidence.min.js +1 -1
  17. data/vendor/assets/javascripts/rx.compat.js +490 -339
  18. data/vendor/assets/javascripts/rx.compat.min.js +2 -2
  19. data/vendor/assets/javascripts/rx.core.compat.js +109 -141
  20. data/vendor/assets/javascripts/rx.core.compat.min.js +1 -1
  21. data/vendor/assets/javascripts/rx.core.js +109 -141
  22. data/vendor/assets/javascripts/rx.core.min.js +1 -1
  23. data/vendor/assets/javascripts/rx.experimental.js +129 -136
  24. data/vendor/assets/javascripts/rx.experimental.min.js +1 -1
  25. data/vendor/assets/javascripts/rx.joinpatterns.js +59 -59
  26. data/vendor/assets/javascripts/rx.joinpatterns.min.js +1 -1
  27. data/vendor/assets/javascripts/rx.js +490 -339
  28. data/vendor/assets/javascripts/rx.lite.compat.js +1099 -954
  29. data/vendor/assets/javascripts/rx.lite.compat.min.js +2 -2
  30. data/vendor/assets/javascripts/rx.lite.extras.min.js +1 -1
  31. data/vendor/assets/javascripts/rx.lite.js +1099 -954
  32. data/vendor/assets/javascripts/rx.lite.min.js +2 -2
  33. data/vendor/assets/javascripts/rx.min.js +2 -2
  34. data/vendor/assets/javascripts/rx.testing.min.js +1 -1
  35. data/vendor/assets/javascripts/rx.time.js +715 -747
  36. data/vendor/assets/javascripts/rx.time.min.js +1 -1
  37. data/vendor/assets/javascripts/rx.virtualtime.min.js +1 -1
  38. 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
- isPromise = Rx.helpers.isPromise,
54
- observableFromPromise = Observable.fromPromise;
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
- function observableTimerDateAndPeriod(dueTime, period, scheduler) {
66
- var p = normalizeTime(period);
67
- return new AnonymousObservable(function (observer) {
68
- var count = 0, d = dueTime;
69
- return scheduler.scheduleRecursiveWithAbsolute(d, function (self) {
70
- var now;
71
- if (p > 0) {
72
- now = scheduler.now();
73
- d = d + p;
74
- if (d <= now) {
75
- d = now + p;
76
- }
77
- }
78
- observer.onNext(count++);
79
- self(d);
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
- function observableTimerTimeSpanAndPeriod(dueTime, period, scheduler) {
95
- if (dueTime === period) {
96
- return new AnonymousObservable(function (observer) {
97
- return scheduler.schedulePeriodicWithState(0, period, function (count) {
98
- observer.onNext(count);
99
- return count + 1;
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
- * Returns an observable sequence that produces a value after each period.
110
- *
111
- * @example
112
- * 1 - res = Rx.Observable.interval(1000);
113
- * 2 - res = Rx.Observable.interval(1000, Rx.Scheduler.timeout);
114
- *
115
- * @param {Number} period Period for producing the values in the resulting sequence (specified as an integer denoting milliseconds).
116
- * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, Rx.Scheduler.timeout is used.
117
- * @returns {Observable} An observable sequence that produces a value after each period.
118
- */
119
- var observableinterval = Observable.interval = function (period, scheduler) {
120
- scheduler || (scheduler = timeoutScheduler);
121
- return observableTimerTimeSpanAndPeriod(period, period, scheduler);
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
- * Returns an observable sequence that produces a value after dueTime has elapsed and then after each period.
126
- *
127
- * @example
128
- * 1 - res = Rx.Observable.timer(new Date());
129
- * 2 - res = Rx.Observable.timer(new Date(), 1000);
130
- * 3 - res = Rx.Observable.timer(new Date(), Rx.Scheduler.timeout);
131
- * 4 - res = Rx.Observable.timer(new Date(), 1000, Rx.Scheduler.timeout);
132
- *
133
- * 5 - res = Rx.Observable.timer(5000);
134
- * 6 - res = Rx.Observable.timer(5000, 1000);
135
- * 7 - res = Rx.Observable.timer(5000, Rx.Scheduler.timeout);
136
- * 8 - res = Rx.Observable.timer(5000, 1000, Rx.Scheduler.timeout);
137
- *
138
- * @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.
139
- * @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.
140
- * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, the timeout scheduler is used.
141
- * @returns {Observable} An observable sequence that produces a value after due time has elapsed and then each period.
142
- */
143
- var observableTimer = Observable.timer = function (dueTime, periodOrScheduler, scheduler) {
144
- var period;
145
- scheduler || (scheduler = timeoutScheduler);
146
- if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'number') {
147
- period = periodOrScheduler;
148
- } else if (periodOrScheduler !== undefined && typeof periodOrScheduler === 'object') {
149
- scheduler = periodOrScheduler;
150
- }
151
- if (dueTime instanceof Date && period === undefined) {
152
- return observableTimerDate(dueTime.getTime(), scheduler);
153
- }
154
- if (dueTime instanceof Date && period !== undefined) {
155
- period = periodOrScheduler;
156
- return observableTimerDateAndPeriod(dueTime.getTime(), period, scheduler);
157
- }
158
- if (period === undefined) {
159
- return observableTimerTimeSpan(dueTime, scheduler);
160
- }
161
- return observableTimerTimeSpanAndPeriod(dueTime, period, scheduler);
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
- function observableDelayTimeSpan(dueTime, scheduler) {
165
- var source = this;
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;
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 (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;
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
- return new CompositeDisposable(subscription, cancelable);
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
- function observableDelayDate(dueTime, scheduler) {
230
- var self = this;
231
- return observableDefer(function () {
232
- var timeSpan = dueTime - scheduler.now();
233
- return observableDelayTimeSpan.call(self, timeSpan, scheduler);
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
- * Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.
239
- *
240
- * @example
241
- * 1 - res = Rx.Observable.delay(new Date());
242
- * 2 - res = Rx.Observable.delay(new Date(), Rx.Scheduler.timeout);
243
- *
244
- * 3 - res = Rx.Observable.delay(5000);
245
- * 4 - res = Rx.Observable.delay(5000, 1000, Rx.Scheduler.timeout);
246
- * @memberOf Observable#
247
- * @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.
248
- * @param {Scheduler} [scheduler] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.
249
- * @returns {Observable} Time-shifted sequence.
250
- */
251
- observableProto.delay = function (dueTime, scheduler) {
252
- scheduler || (scheduler = timeoutScheduler);
253
- return dueTime instanceof Date ?
254
- observableDelayDate.call(this, dueTime.getTime(), scheduler) :
255
- observableDelayTimeSpan.call(this, dueTime, scheduler);
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
- * Ignores values from an observable sequence which are followed by another value before dueTime.
260
- *
261
- * @example
262
- * 1 - res = source.throttle(5000); // 5 seconds
263
- * 2 - res = source.throttle(5000, scheduler);
264
- *
265
- * @param {Number} dueTime Duration of the throttle period for each value (specified as an integer denoting milliseconds).
266
- * @param {Scheduler} [scheduler] Scheduler to run the throttle timers on. If not specified, the timeout scheduler is used.
267
- * @returns {Observable} The throttled sequence.
268
- */
269
- observableProto.throttle = function (dueTime, scheduler) {
270
- scheduler || (scheduler = timeoutScheduler);
271
- var source = this;
272
- return this.throttleWithSelector(function () { return observableTimer(dueTime, scheduler); })
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
- * Projects each element of an observable sequence into zero or more windows which are produced based on timing information.
277
- *
278
- * @example
279
- * 1 - res = xs.windowWithTime(1000, scheduler); // non-overlapping segments of 1 second
280
- * 2 - res = xs.windowWithTime(1000, 500 , scheduler); // segments of 1 second with time shift 0.5 seconds
281
- *
282
- * @param {Number} timeSpan Length of each window (specified as an integer denoting milliseconds).
283
- * @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.
284
- * @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
285
- * @returns {Observable} An observable sequence of windows.
286
- */
287
- observableProto.windowWithTime = function (timeSpan, timeShiftOrScheduler, scheduler) {
288
- var source = this, timeShift;
289
- if (timeShiftOrScheduler === undefined) {
290
- timeShift = timeSpan;
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
- if (scheduler === undefined) {
293
- scheduler = timeoutScheduler;
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
- if (typeof timeShiftOrScheduler === 'number') {
296
- timeShift = timeShiftOrScheduler;
297
- } else if (typeof timeShiftOrScheduler === 'object') {
298
- timeShift = timeSpan;
299
- scheduler = timeShiftOrScheduler;
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
- return new AnonymousObservable(function (observer) {
302
- var groupDisposable,
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
- function createTimer () {
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
- * 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.
378
- * @example
379
- * 1 - res = source.windowWithTimeOrCount(5000, 50); // 5s or 50 items
380
- * 2 - res = source.windowWithTimeOrCount(5000, 50, scheduler); //5s or 50 items
381
- *
382
- * @memberOf Observable#
383
- * @param {Number} timeSpan Maximum time length of a window.
384
- * @param {Number} count Maximum element count of a window.
385
- * @param {Scheduler} [scheduler] Scheduler to run windowing timers on. If not specified, the timeout scheduler is used.
386
- * @returns {Observable} An observable sequence of windows.
387
- */
388
- observableProto.windowWithTimeOrCount = function (timeSpan, count, scheduler) {
389
- var source = this;
390
- scheduler || (scheduler = timeoutScheduler);
391
- return new AnonymousObservable(function (observer) {
392
- var createTimer,
393
- groupDisposable,
394
- n = 0,
395
- refCountDisposable,
396
- s,
397
- timerD = new SerialDisposable(),
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
- createTimer(0);
420
- groupDisposable.add(source.subscribe(function (x) {
421
- var newId = 0, newWindow = false;
422
- s.onNext(x);
423
- n++;
424
- if (n === count) {
425
- newWindow = true;
426
- n = 0;
427
- newId = ++windowId;
428
- s.onCompleted();
429
- s = new Subject();
430
- observer.onNext(addRef(s, refCountDisposable));
431
- }
432
- if (newWindow) {
433
- createTimer(newId);
434
- }
435
- }, function (e) {
436
- s.onError(e);
437
- observer.onError(e);
438
- }, function () {
439
- s.onCompleted();
440
- observer.onCompleted();
441
- }));
442
- return refCountDisposable;
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
- * Records the time interval between consecutive values in an observable sequence.
482
- *
483
- * @example
484
- * 1 - res = source.timeInterval();
485
- * 2 - res = source.timeInterval(Rx.Scheduler.timeout);
486
- *
487
- * @param [scheduler] Scheduler used to compute time intervals. If not specified, the timeout scheduler is used.
488
- * @returns {Observable} An observable sequence with time interval information on values.
489
- */
490
- observableProto.timeInterval = function (scheduler) {
491
- var source = this;
492
- scheduler || (scheduler = timeoutScheduler);
493
- return observableDefer(function () {
494
- var last = scheduler.now();
495
- return source.select(function (x) {
496
- var now = scheduler.now(), span = now - last;
497
- last = now;
498
- return {
499
- value: x,
500
- interval: span
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
- * Records the timestamp for each value in an observable sequence.
508
- *
509
- * @example
510
- * 1 - res = source.timestamp(); // produces { value: x, timestamp: ts }
511
- * 2 - res = source.timestamp(Rx.Scheduler.timeout);
512
- *
513
- * @param {Scheduler} [scheduler] Scheduler used to compute timestamps. If not specified, the timeout scheduler is used.
514
- * @returns {Observable} An observable sequence with timestamp information on values.
515
- */
516
- observableProto.timestamp = function (scheduler) {
517
- scheduler || (scheduler = timeoutScheduler);
518
- return this.select(function (x) {
519
- return {
520
- value: x,
521
- timestamp: scheduler.now()
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
- function sampleObservable(source, sampler) {
527
-
528
- return new AnonymousObservable(function (observer) {
529
- var atEnd, value, hasValue;
509
+ function sampleObservable(source, sampler) {
510
+
511
+ return new AnonymousObservable(function (observer) {
512
+ var atEnd, value, hasValue;
530
513
 
531
- function sampleSubscribe() {
532
- if (hasValue) {
533
- hasValue = false;
534
- observer.onNext(value);
535
- }
536
- if (atEnd) {
537
- observer.onCompleted();
538
- }
539
- }
514
+ function sampleSubscribe() {
515
+ if (hasValue) {
516
+ hasValue = false;
517
+ observer.onNext(value);
518
+ }
519
+ atEnd && observer.onCompleted();
520
+ }
540
521
 
541
- return new CompositeDisposable(
542
- source.subscribe(function (newValue) {
543
- hasValue = true;
544
- value = newValue;
545
- }, observer.onError.bind(observer), function () {
546
- atEnd = true;
547
- }),
548
- sampler.subscribe(sampleSubscribe, observer.onError.bind(observer), sampleSubscribe)
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
- * Samples the observable sequence at each interval.
555
- *
556
- * @example
557
- * 1 - res = source.sample(sampleObservable); // Sampler tick sequence
558
- * 2 - res = source.sample(5000); // 5 seconds
559
- * 2 - res = source.sample(5000, Rx.Scheduler.timeout); // 5 seconds
560
- *
561
- * @param {Mixed} intervalOrSampler Interval at which to sample (specified as an integer denoting milliseconds) or Sampler Observable.
562
- * @param {Scheduler} [scheduler] Scheduler to run the sampling timer on. If not specified, the timeout scheduler is used.
563
- * @returns {Observable} Sampled observable sequence.
564
- */
565
- observableProto.sample = function (intervalOrSampler, scheduler) {
566
- scheduler || (scheduler = timeoutScheduler);
567
- if (typeof intervalOrSampler === 'number') {
568
- return sampleObservable(this, observableinterval(intervalOrSampler, scheduler));
569
- }
570
- return sampleObservable(this, intervalOrSampler);
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
- * Generates an observable sequence by iterating a state from an initial state until the condition fails.
641
- *
642
- * @example
643
- * res = source.generateWithAbsoluteTime(0,
644
- * function (x) { return return true; },
645
- * function (x) { return x + 1; },
646
- * function (x) { return x; },
647
- * function (x) { return new Date(); }
648
- * });
649
- *
650
- * @param {Mixed} initialState Initial state.
651
- * @param {Function} condition Condition to terminate generation (upon returning false).
652
- * @param {Function} iterate Iteration step function.
653
- * @param {Function} resultSelector Selector function for results produced in the sequence.
654
- * @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning Date values.
655
- * @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
656
- * @returns {Observable} The generated sequence.
657
- */
658
- Observable.generateWithAbsoluteTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
659
- scheduler || (scheduler = timeoutScheduler);
660
- return new AnonymousObservable(function (observer) {
661
- var first = true,
662
- hasResult = false,
663
- result,
664
- state = initialState,
665
- time;
666
- return scheduler.scheduleRecursiveWithAbsolute(scheduler.now(), function (self) {
667
- if (hasResult) {
668
- observer.onNext(result);
669
- }
670
- try {
671
- if (first) {
672
- first = false;
673
- } else {
674
- state = iterate(state);
675
- }
676
- hasResult = condition(state);
677
- if (hasResult) {
678
- result = resultSelector(state);
679
- time = timeSelector(state);
680
- }
681
- } catch (e) {
682
- observer.onError(e);
683
- return;
684
- }
685
- if (hasResult) {
686
- self(time);
687
- } else {
688
- observer.onCompleted();
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
- * Generates an observable sequence by iterating a state from an initial state until the condition fails.
696
- *
697
- * @example
698
- * res = source.generateWithRelativeTime(0,
699
- * function (x) { return return true; },
700
- * function (x) { return x + 1; },
701
- * function (x) { return x; },
702
- * function (x) { return 500; }
703
- * );
704
- *
705
- * @param {Mixed} initialState Initial state.
706
- * @param {Function} condition Condition to terminate generation (upon returning false).
707
- * @param {Function} iterate Iteration step function.
708
- * @param {Function} resultSelector Selector function for results produced in the sequence.
709
- * @param {Function} timeSelector Time selector function to control the speed of values being produced each iteration, returning integer values denoting milliseconds.
710
- * @param {Scheduler} [scheduler] Scheduler on which to run the generator loop. If not specified, the timeout scheduler is used.
711
- * @returns {Observable} The generated sequence.
712
- */
713
- Observable.generateWithRelativeTime = function (initialState, condition, iterate, resultSelector, timeSelector, scheduler) {
714
- scheduler || (scheduler = timeoutScheduler);
715
- return new AnonymousObservable(function (observer) {
716
- var first = true,
717
- hasResult = false,
718
- result,
719
- state = initialState,
720
- time;
721
- return scheduler.scheduleRecursiveWithRelative(0, function (self) {
722
- if (hasResult) {
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
- * Time shifts the observable sequence by delaying the subscription.
751
- *
752
- * @example
753
- * 1 - res = source.delaySubscription(5000); // 5s
754
- * 2 - res = source.delaySubscription(5000, Rx.Scheduler.timeout); // 5 seconds
755
- *
756
- * @param {Number} dueTime Absolute or relative time to perform the subscription at.
757
- * @param {Scheduler} [scheduler] Scheduler to run the subscription delay timer on. If not specified, the timeout scheduler is used.
758
- * @returns {Observable} Time-shifted sequence.
759
- */
760
- observableProto.delaySubscription = function (dueTime, scheduler) {
761
- scheduler || (scheduler = timeoutScheduler);
762
- return this.delayWithSelector(observableTimer(dueTime, scheduler), function () { return observableEmpty(); });
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
- * Ignores values from an observable sequence which are followed by another value within a computed throttle duration.
911
- *
912
- * @example
913
- * 1 - res = source.delayWithSelector(function (x) { return Rx.Scheduler.timer(x + x); });
914
- *
915
- * @param {Function} throttleDurationSelector Selector function to retrieve a sequence indicating the throttle duration for each given element.
916
- * @returns {Observable} The throttled sequence.
917
- */
918
- observableProto.throttleWithSelector = function (throttleDurationSelector) {
919
- var source = this;
920
- return new AnonymousObservable(function (observer) {
921
- var value, hasValue = false, cancelable = new SerialDisposable(), id = 0, subscription = source.subscribe(function (x) {
922
- var throttle;
923
- try {
924
- throttle = throttleDurationSelector(x);
925
- } catch (e) {
926
- observer.onError(e);
927
- return;
928
- }
929
- hasValue = true;
930
- value = x;
931
- id++;
932
- var currentid = id, d = new SingleAssignmentDisposable();
933
- cancelable.setDisposable(d);
934
- d.setDisposable(throttle.subscribe(function () {
935
- if (hasValue && id === currentid) {
936
- observer.onNext(value);
937
- }
938
- hasValue = false;
939
- d.dispose();
940
- }, observer.onError.bind(observer), function () {
941
- if (hasValue && id === currentid) {
942
- observer.onNext(value);
943
- }
944
- hasValue = false;
945
- d.dispose();
946
- }));
947
- }, function (e) {
948
- cancelable.dispose();
949
- observer.onError(e);
950
- hasValue = false;
951
- id++;
952
- }, function () {
953
- cancelable.dispose();
954
- if (hasValue) {
955
- observer.onNext(value);
956
- }
957
- observer.onCompleted();
958
- hasValue = false;
959
- id++;
960
- });
961
- return new CompositeDisposable(subscription, cancelable);
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
- * Skips elements for the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.
967
- *
968
- * 1 - res = source.skipLastWithTime(5000);
969
- * 2 - res = source.skipLastWithTime(5000, scheduler);
970
- *
971
- * @description
972
- * This operator accumulates a queue with a length enough to store elements received during the initial duration window.
973
- * As more elements are received, elements older than the specified duration are taken from the queue and produced on the
974
- * result sequence. This causes elements to be delayed with duration.
975
- * @param {Number} duration Duration for skipping elements from the end of the sequence.
976
- * @param {Scheduler} [scheduler] Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout
977
- * @returns {Observable} An observable sequence with the elements skipped during the specified duration from the end of the source sequence.
978
- */
979
- observableProto.skipLastWithTime = function (duration, scheduler) {
980
- scheduler || (scheduler = timeoutScheduler);
981
- var source = this;
982
- return new AnonymousObservable(function (observer) {
983
- var q = [];
984
- return source.subscribe(function (x) {
985
- var now = scheduler.now();
986
- q.push({ interval: now, value: x });
987
- while (q.length > 0 && now - q[0].interval >= duration) {
988
- observer.onNext(q.shift().value);
989
- }
990
- }, observer.onError.bind(observer), function () {
991
- var now = scheduler.now();
992
- while (q.length > 0 && now - q[0].interval >= duration) {
993
- observer.onNext(q.shift().value);
994
- }
995
- observer.onCompleted();
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
- * 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.
1020
- *
1021
- * @example
1022
- * 1 - res = source.takeLastBufferWithTime(5000, [optional scheduler]);
1023
- * @description
1024
- * This operator accumulates a queue with a length enough to store elements received during the initial duration window.
1025
- * As more elements are received, elements older than the specified duration are taken from the queue and produced on the
1026
- * result sequence. This causes elements to be delayed with duration.
1027
- * @param {Number} duration Duration for taking elements from the end of the sequence.
1028
- * @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
1029
- * @returns {Observable} An observable sequence containing a single array with the elements taken during the specified duration from the end of the source sequence.
1030
- */
1031
- observableProto.takeLastBufferWithTime = function (duration, scheduler) {
1032
- var source = this;
1033
- scheduler || (scheduler = timeoutScheduler);
1034
- return new AnonymousObservable(function (observer) {
1035
- var q = [];
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
- * Takes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
1060
- *
1061
- * @example
1062
- * 1 - res = source.takeWithTime(5000, [optional scheduler]);
1063
- * @description
1064
- * This operator accumulates a queue with a length enough to store elements received during the initial duration window.
1065
- * As more elements are received, elements older than the specified duration are taken from the queue and produced on the
1066
- * result sequence. This causes elements to be delayed with duration.
1067
- * @param {Number} duration Duration for taking elements from the start of the sequence.
1068
- * @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
1069
- * @returns {Observable} An observable sequence with the elements taken during the specified duration from the start of the source sequence.
1070
- */
1071
- observableProto.takeWithTime = function (duration, scheduler) {
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
- return new CompositeDisposable(t, source.subscribe(observer));
1080
- });
1081
- };
1029
+ observer.onNext(res);
1030
+ observer.onCompleted();
1031
+ });
1032
+ });
1033
+ };
1082
1034
 
1083
- /**
1084
- * Skips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
1085
- *
1086
- * @example
1087
- * 1 - res = source.skipWithTime(5000, [optional scheduler]);
1088
- *
1089
- * @description
1090
- * Specifying a zero value for duration doesn't guarantee no elements will be dropped from the start of the source sequence.
1091
- * 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
1092
- * may not execute immediately, despite the zero due time.
1093
- *
1094
- * Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the duration.
1095
- * @param {Number} duration Duration for skipping elements from the start of the sequence.
1096
- * @param {Scheduler} scheduler Scheduler to run the timer on. If not specified, defaults to Rx.Scheduler.timeout.
1097
- * @returns {Observable} An observable sequence with the elements skipped during the specified duration from the start of the source sequence.
1098
- */
1099
- observableProto.skipWithTime = function (duration, scheduler) {
1100
- var source = this;
1101
- scheduler || (scheduler = timeoutScheduler);
1102
- return new AnonymousObservable(function (observer) {
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
- return new CompositeDisposable(t, d);
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';