/
nested2.html
88 lines (77 loc) · 3.38 KB
/
nested2.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
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>nested objects 2 test</title>
<script src="test-config.js"></script>
<script type="text/javascript">
// The root context
wire = {
a: -1
};
</script>
<script type="text/javascript">
// This wires a direct child of the root context, adding
// nothing to it. So context0 is *not* the root context, but
// rather it's child.
// This chain creates the hierarchy:
// root (defined above)
// - context 0
// - context 1
// - context 2
// - context 3
require(['wire'], function(wire) {
wire({ a: 0 }).then(function(context0) {
doh.register('nested2-root', function(doh) {
// context0 is a child of the root context, but added nothing
doh.assertEqual(0, context0.a);
});
// Wire a child of context0, and override a
context0.wire({ a: 1 }).then(function(context1) {
doh.register('nested2-0', function(doh) {
// context1 is the child of context0
doh.assertEqual(0, context0.a);
doh.assertEqual(1, context1.a);
});
// Wire a child of context1, and override a again
context1.wire({ a: 2 }).then(function(context2) {
doh.register('nested2-1', function(doh) {
// context2 is the child of context1
doh.assertEqual(0, context0.a);
doh.assertEqual(1, context1.a);
doh.assertEqual(2, context2.a);
});
// Wire a child of context2, and override a again
context2.wire({ a: 3 }).then(function(context3) {
doh.register('nested2-2a', function(doh) {
// context3 is the child of context2
doh.assertEqual(0, context0.a);
doh.assertEqual(1, context1.a);
doh.assertEqual(2, context2.a);
doh.assertEqual(3, context3.a);
});
doh.register('nested2-2b', function(doh) {
var dohd = new doh.Deferred();
// This will destroy all contexts except the root
context0.destroy().then(function() {
// a will be deleted from all contexts
// except the root context
var success = -1 === context0.a
&& -1 === context1.a
&& -1 === context2.a
&& -1 === context3.a;
dohd.callback(success);
});
return dohd;
});
doh.run();
});
});
});
});
});
</script>
</head>
<body>
</body>
</html>