-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefer.html
43 lines (37 loc) · 1.19 KB
/
defer.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/rxjs/5.4.0/Rx.min.js"></script>
</head>
<body>
<script>
//eg
/*
var clicksOrInterval = Rx.Observable.defer(function () {
if (Math.random() > 0.5) {
return Rx.Observable.fromEvent(document, 'click');
} else {
return Rx.Observable.interval(1000);
}
});
clicksOrInterval.subscribe(x => console.log(x));
*/
//f-eg
/* Using an observable sequence */
/* Using a promise */
// var source = Rx.Observable.defer(() => Rx.Promise.resolve(42));
// var subscription = source.subscribe(
// x => console.log(`onNext: ${x}`),
// e => console.log(`onError: ${e}`),
// () => console.log('onCompleted'));
// => onNext: 42
// => onCompleted
// => onNext: 42
// => onCompleted
</script>
</body>
</html>