-
Notifications
You must be signed in to change notification settings - Fork 0
/
testscheduler.js
97 lines (84 loc) · 2.43 KB
/
testscheduler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***
* Excerpted from "Reactive Programming with RxJS",
* published by The Pragmatic Bookshelf.
* Copyrights apply to this code. It may not be used to create training material,
* courses, books, articles, and the like. Contact us if you are in doubt.
* We make no guarantees that this code is fit for any purpose.
* Visit http://www.pragmaticprogrammer.com/titles/smreactjs for more book information.
***/
var Rx = require("Rx");
var onNext = Rx.ReactiveTest.onNext; // (1)
var onCompleted = Rx.ReactiveTest.onCompleted;
var scheduler = new Rx.TestScheduler(); // (2)
var quakes = scheduler.createColdObservable( // (3)
onNext(100, { properties: 1 }),
onNext(300, { properties: 2 }),
onNext(550, { properties: 3 }),
onNext(750, { properties: 4 }),
onNext(1000, { properties: 5 }),
onCompleted(1100)
);
QUnit.test("Test quake buffering", function(assert) { // (4)
var results = scheduler.startScheduler(function() { // (5)
return quakeBatches(scheduler)
}, {
created: 0,
subscribed: 0,
disposed: 1200
});
var messages = results.messages; // (6)
console.log(messages[0]);
assert.equal( // (7)
messages[0].toString(),
onNext(501, [1, 2]).toString()
);
assert.equal(
messages[1].toString(),
onNext(1001, [3, 4, 5]).toString()
);
assert.equal(
messages[2].toString(),
onCompleted(1101).toString()
);
});
function quakeBatches(scheduler) {
return quakes.pluck('properties')
.bufferWithTime(500, null, scheduler || null)
.filter(function(rows) {
return rows.length > 0;
});
}
var onNext = Rx.ReactiveTest.onNext;
QUnit.test("Test value order", function(assert) {
var scheduler = new Rx.TestScheduler();
var subject = scheduler.createHotObservable(
onNext(100, 'first'),
onNext(200, 'second'),
onNext(300, 'third')
);
var result = '';
subject.subscribe(function(value) { result = value });
scheduler.advanceBy(100);
assert.equal(result, 'first');
scheduler.advanceBy(100);
assert.equal(result, 'second');
scheduler.advanceBy(100);
assert.equal(result, 'third');
});
/*
quakes
.pluck('properties')
.map(makeRow)
.bufferWithTime(500)
.filter(function(rows) { return rows.length > 0; })
.map(function(rows) {
var fragment = document.createDocumentFragment();
rows.forEach(function(row) {
fragment.appendChild(row);
});
return fragment;
})
.subscribe(function(fragment) {
table.appendChild(fragment);
});
*/