-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathtest$watch.html
91 lines (88 loc) · 3.05 KB
/
test$watch.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
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
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<!-- <script>
window.onload = function() {
var paths = ["avalon","map","set", "util", "path"]
paths.forEach(function(path) {
var node = document.createElement("script")
node.src = path+".js"
document.head.appendChild(node)
})
}
</script>-->
<!-- <script src="observe.js">
</script>
<script>
var obj = {foo: {bar: 'baz'}};
var observer = new PathObserver(obj, 'foo.bar');
observer.open(function(newValue, oldValue) {
console.log(newValue, oldValue)
// respond to obj.foo.bar having changed value.
});
obj.foo.bar = 1
console.log(observer)
setTimeout(function() {
obj.foo.bar = 4
})
</script>-->
<script src="avalon2.js"></script>
<script>
var vmodel = avalon.define({
$id: "xxx",
a: 1,
arr: [4, 5],
b: {
c: 2
},
ddd: {
ccc: {
bbb: {
aaa: 3
}
}
}
})
vmodel.$watch("a", function(a, b, c) {
console.log(this, a, b, c)
})
vmodel.b.$watch("c", function(v) {
console.log("b下面的c值发生改变了", v)
})
vmodel.arr.$watch("[*]", function(v) {
console.log("数组监听自己的元素变化", v)
})
vmodel.arr.$watch("length", function(v) {
console.log("length", v)
})
vmodel.$watch("b.c", function(a, b, c) {
console.log("fire b.c ", a, b,c)
})
vmodel.$watch("arr[*]", function(a, b, c) {
console.log("父对象监听子数组元素变化 ", a, b,c ,this)
})
vmodel.$watch("ddd.ccc.bbb.aaa", function(a, b, c) {
console.log("深层对象监听 ", a, b, c, this)
})
setTimeout(function() {
vmodel.a = "xxx"
})
setTimeout(function() {
vmodel.b.c = 9
})
setTimeout(function() {
vmodel.arr[0] = 10000
})
setTimeout(function() {
vmodel.arr.push(12)
vmodel.ddd.ccc.bbb.aaa = 999
})
</script>
</head>
<body>
<div>TODO write content</div>
</body>
</html>