-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest4.html
48 lines (40 loc) · 1.29 KB
/
test4.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
44
45
46
47
48
<!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>
//错误示例
var subject = new Rx.BehaviorSubject();
var arr = [1,2,3,4]
setTimeout(function() {
arr.push(5)
}, 5000);
function getArr(){
return Promise.resolve(arr);
}
var observable= Rx.Observable.fromPromise(getArr());
// observable.subscribe(subject);
console.log(observable)
subject.subscribe(x => console.log(x))
setTimeout(function() {
subject.subscribe(x => console.log(x))
}, 1000);
subject.next(888)
// var subject = new Rx.Subject();
// subject.subscribe({
// next: (v) => console.log('observerA: ' + v)
// });
// subject.subscribe({
// next: (v) => console.log('observerB: ' + v)
// });
// var observable = Rx.Observable.from([1, 2, 3]);
// observable.subscribe(subject); // You can su
</script>
</body>
</html>