glass-easel 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/dist/glass_easel.all.d.ts +1 -0
- package/dist/glass_easel.all.js +2 -0
- package/dist/glass_easel.all.js.map +1 -0
- package/dist/glass_easel.domlike.global.d.ts +1 -0
- package/dist/glass_easel.domlike.global.js +2 -0
- package/dist/glass_easel.domlike.global.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/src/backend/backend_protocol.d.ts +119 -0
- package/dist/types/src/backend/backend_protocol.d.ts.map +1 -0
- package/dist/types/src/backend/composed_backend_protocol.d.ts +90 -0
- package/dist/types/src/backend/composed_backend_protocol.d.ts.map +1 -0
- package/dist/types/src/backend/domlike_backend_protocol.d.ts +76 -0
- package/dist/types/src/backend/domlike_backend_protocol.d.ts.map +1 -0
- package/dist/types/src/backend/mode.d.ts +46 -0
- package/dist/types/src/backend/mode.d.ts.map +1 -0
- package/dist/types/src/backend/suggested_backend_protocol.d.ts +30 -0
- package/dist/types/src/backend/suggested_backend_protocol.d.ts.map +1 -0
- package/dist/types/src/behavior.d.ts +428 -0
- package/dist/types/src/behavior.d.ts.map +1 -0
- package/dist/types/src/class_list.d.ts +79 -0
- package/dist/types/src/class_list.d.ts.map +1 -0
- package/dist/types/src/component.d.ts +291 -0
- package/dist/types/src/component.d.ts.map +1 -0
- package/dist/types/src/component_params.d.ts +239 -0
- package/dist/types/src/component_params.d.ts.map +1 -0
- package/dist/types/src/component_space.d.ts +164 -0
- package/dist/types/src/component_space.d.ts.map +1 -0
- package/dist/types/src/data_path.d.ts +5 -0
- package/dist/types/src/data_path.d.ts.map +1 -0
- package/dist/types/src/data_proxy.d.ts +107 -0
- package/dist/types/src/data_proxy.d.ts.map +1 -0
- package/dist/types/src/data_utils.d.ts +3 -0
- package/dist/types/src/data_utils.d.ts.map +1 -0
- package/dist/types/src/element.d.ts +275 -0
- package/dist/types/src/element.d.ts.map +1 -0
- package/dist/types/src/element_iterator.d.ts +43 -0
- package/dist/types/src/element_iterator.d.ts.map +1 -0
- package/dist/types/src/event.d.ts +104 -0
- package/dist/types/src/event.d.ts.map +1 -0
- package/dist/types/src/external_shadow_tree.d.ts +20 -0
- package/dist/types/src/external_shadow_tree.d.ts.map +1 -0
- package/dist/types/src/func_arr.d.ts +39 -0
- package/dist/types/src/func_arr.d.ts.map +1 -0
- package/dist/types/src/global_options.d.ts +111 -0
- package/dist/types/src/global_options.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +43 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/mutation_observer.d.ts +79 -0
- package/dist/types/src/mutation_observer.d.ts.map +1 -0
- package/dist/types/src/native_node.d.ts +8 -0
- package/dist/types/src/native_node.d.ts.map +1 -0
- package/dist/types/src/node.d.ts +49 -0
- package/dist/types/src/node.d.ts.map +1 -0
- package/dist/types/src/relation.d.ts +47 -0
- package/dist/types/src/relation.d.ts.map +1 -0
- package/dist/types/src/render.d.ts +3 -0
- package/dist/types/src/render.d.ts.map +1 -0
- package/dist/types/src/selector.d.ts +32 -0
- package/dist/types/src/selector.d.ts.map +1 -0
- package/dist/types/src/shadow_root.d.ts +136 -0
- package/dist/types/src/shadow_root.d.ts.map +1 -0
- package/dist/types/src/template_engine.d.ts +18 -0
- package/dist/types/src/template_engine.d.ts.map +1 -0
- package/dist/types/src/text_node.d.ts +32 -0
- package/dist/types/src/text_node.d.ts.map +1 -0
- package/dist/types/src/tmpl/index.d.ts +18 -0
- package/dist/types/src/tmpl/index.d.ts.map +1 -0
- package/dist/types/src/tmpl/native_rendering.d.ts +45 -0
- package/dist/types/src/tmpl/native_rendering.d.ts.map +1 -0
- package/dist/types/src/tmpl/proc_gen_wrapper.d.ts +80 -0
- package/dist/types/src/tmpl/proc_gen_wrapper.d.ts.map +1 -0
- package/dist/types/src/tmpl/proc_gen_wrapper_dom.d.ts +50 -0
- package/dist/types/src/tmpl/proc_gen_wrapper_dom.d.ts.map +1 -0
- package/dist/types/src/tmpl/range_list_diff.d.ts +19 -0
- package/dist/types/src/tmpl/range_list_diff.d.ts.map +1 -0
- package/dist/types/src/trait_behaviors.d.ts +38 -0
- package/dist/types/src/trait_behaviors.d.ts.map +1 -0
- package/dist/types/src/virtual_node.d.ts +10 -0
- package/dist/types/src/virtual_node.d.ts.map +1 -0
- package/dist/types/tests/backend/domlike.test.d.ts +2 -0
- package/dist/types/tests/backend/domlike.test.d.ts.map +1 -0
- package/dist/types/tests/base/env.d.ts +29 -0
- package/dist/types/tests/base/env.d.ts.map +1 -0
- package/dist/types/tests/base/match.d.ts +9 -0
- package/dist/types/tests/base/match.d.ts.map +1 -0
- package/dist/types/tests/core/backend.test.d.ts +2 -0
- package/dist/types/tests/core/backend.test.d.ts.map +1 -0
- package/dist/types/tests/core/behavior.test.d.ts +2 -0
- package/dist/types/tests/core/behavior.test.d.ts.map +1 -0
- package/dist/types/tests/core/component_space.test.d.ts +2 -0
- package/dist/types/tests/core/component_space.test.d.ts.map +1 -0
- package/dist/types/tests/core/data_update.test.d.ts +2 -0
- package/dist/types/tests/core/data_update.test.d.ts.map +1 -0
- package/dist/types/tests/core/misc.test.d.ts +2 -0
- package/dist/types/tests/core/misc.test.d.ts.map +1 -0
- package/dist/types/tests/core/placeholder.test.d.ts +2 -0
- package/dist/types/tests/core/placeholder.test.d.ts.map +1 -0
- package/dist/types/tests/core/slot.test.d.ts +2 -0
- package/dist/types/tests/core/slot.test.d.ts.map +1 -0
- package/dist/types/tests/core/trait_behaviors.test.d.ts +2 -0
- package/dist/types/tests/core/trait_behaviors.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/binding_map.test.d.ts +2 -0
- package/dist/types/tests/tmpl/binding_map.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/event.test.d.ts +2 -0
- package/dist/types/tests/tmpl/event.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/expression.test.d.ts +2 -0
- package/dist/types/tests/tmpl/expression.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/lvalue.test.d.ts +2 -0
- package/dist/types/tests/tmpl/lvalue.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/native_rendering.test.d.ts +2 -0
- package/dist/types/tests/tmpl/native_rendering.test.d.ts.map +1 -0
- package/dist/types/tests/tmpl/structure.test.d.ts +2 -0
- package/dist/types/tests/tmpl/structure.test.d.ts.map +1 -0
- package/dist/types/tests/types/chaining.test.d.ts +2 -0
- package/dist/types/tests/types/chaining.test.d.ts.map +1 -0
- package/dist/types/tests/types/createElement.test.d.ts +2 -0
- package/dist/types/tests/types/createElement.test.d.ts.map +1 -0
- package/dist/types/tests/types/definition.test.d.ts +2 -0
- package/dist/types/tests/types/definition.test.d.ts.map +1 -0
- package/guide/zh_CN/advanced/binding_map_update.md +32 -0
- package/guide/zh_CN/advanced/build_args.md +28 -0
- package/guide/zh_CN/advanced/component_filter.md +70 -0
- package/guide/zh_CN/advanced/component_space.md +124 -0
- package/guide/zh_CN/advanced/custom_backend.md +53 -0
- package/guide/zh_CN/advanced/error_listener.md +32 -0
- package/guide/zh_CN/advanced/external_component.md +73 -0
- package/guide/zh_CN/advanced/template_engine.md +61 -0
- package/guide/zh_CN/appendix/backend_protocol.md +501 -0
- package/guide/zh_CN/appendix/list_diff_algorithm.md +406 -0
- package/guide/zh_CN/basic/beginning.md +94 -0
- package/guide/zh_CN/basic/component.md +156 -0
- package/guide/zh_CN/basic/event.md +169 -0
- package/guide/zh_CN/basic/lifetime.md +66 -0
- package/guide/zh_CN/basic/method.md +62 -0
- package/guide/zh_CN/basic/template.md +135 -0
- package/guide/zh_CN/data_management/advanced_update.md +170 -0
- package/guide/zh_CN/data_management/data_deep_copy.md +157 -0
- package/guide/zh_CN/data_management/data_observer.md +154 -0
- package/guide/zh_CN/data_management/property_early_init.md +31 -0
- package/guide/zh_CN/data_management/pure_data_pattern.md +21 -0
- package/guide/zh_CN/index.md +93 -0
- package/guide/zh_CN/interaction/behavior.md +52 -0
- package/guide/zh_CN/interaction/component_path.md +37 -0
- package/guide/zh_CN/interaction/generic.md +73 -0
- package/guide/zh_CN/interaction/placeholder.md +40 -0
- package/guide/zh_CN/interaction/relation.md +151 -0
- package/guide/zh_CN/interaction/slot.md +137 -0
- package/guide/zh_CN/interaction/template_import.md +94 -0
- package/guide/zh_CN/interaction/trait_behavior.md +117 -0
- package/guide/zh_CN/styling/external_class.md +46 -0
- package/guide/zh_CN/styling/style_isolation.md +54 -0
- package/guide/zh_CN/styling/virtual_host.md +52 -0
- package/guide/zh_CN/tree/element_iterator.md +54 -0
- package/guide/zh_CN/tree/mutation_observer.md +52 -0
- package/guide/zh_CN/tree/node_tree.md +142 -0
- package/guide/zh_CN/tree/node_tree_modification.md +78 -0
- package/guide/zh_CN/tree/selector.md +66 -0
- package/jest.config.js +6 -0
- package/jest.dts.config.js +9 -0
- package/jest.unit.config.js +14 -0
- package/package.json +28 -0
- package/src/backend/backend_protocol.ts +313 -0
- package/src/backend/composed_backend_protocol.ts +252 -0
- package/src/backend/domlike_backend_protocol.ts +370 -0
- package/src/backend/mode.ts +51 -0
- package/src/backend/suggested_backend_protocol.ts +83 -0
- package/src/behavior.ts +1655 -0
- package/src/bootstrap_dom_dev.js +22 -0
- package/src/class_list.ts +376 -0
- package/src/component.ts +1309 -0
- package/src/component_params.ts +461 -0
- package/src/component_space.ts +547 -0
- package/src/data_path.ts +225 -0
- package/src/data_proxy.ts +670 -0
- package/src/data_utils.ts +50 -0
- package/src/element.ts +1966 -0
- package/src/element_iterator.ts +158 -0
- package/src/event.ts +401 -0
- package/src/external_shadow_tree.ts +27 -0
- package/src/func_arr.ts +198 -0
- package/src/global_options.ts +242 -0
- package/src/index.ts +187 -0
- package/src/mutation_observer.ts +252 -0
- package/src/native_node.ts +74 -0
- package/src/node.ts +174 -0
- package/src/relation.ts +380 -0
- package/src/render.ts +25 -0
- package/src/selector.ts +218 -0
- package/src/shadow_root.ts +766 -0
- package/src/template_engine.ts +45 -0
- package/src/text_node.ts +149 -0
- package/src/tmpl/index.ts +199 -0
- package/src/tmpl/native_rendering.ts +175 -0
- package/src/tmpl/proc_gen_wrapper.ts +954 -0
- package/src/tmpl/proc_gen_wrapper_dom.ts +230 -0
- package/src/tmpl/range_list_diff.ts +443 -0
- package/src/trait_behaviors.ts +51 -0
- package/src/virtual_node.ts +51 -0
- package/tests/backend/domlike.test.ts +254 -0
- package/tests/base/env.ts +78 -0
- package/tests/base/match.ts +185 -0
- package/tests/core/backend.test.ts +144 -0
- package/tests/core/behavior.test.ts +546 -0
- package/tests/core/component_space.test.ts +212 -0
- package/tests/core/data_update.test.ts +461 -0
- package/tests/core/misc.test.ts +339 -0
- package/tests/core/placeholder.test.ts +180 -0
- package/tests/core/slot.test.ts +1495 -0
- package/tests/core/trait_behaviors.test.ts +153 -0
- package/tests/legacy/README.md +3 -0
- package/tests/legacy/behavior.test.js +293 -0
- package/tests/legacy/component.test.js +1247 -0
- package/tests/legacy/data_path.test.js +149 -0
- package/tests/legacy/data_proxy.test.js +759 -0
- package/tests/legacy/element_iterator.test.js +148 -0
- package/tests/legacy/event.test.js +849 -0
- package/tests/legacy/external.test.js +510 -0
- package/tests/legacy/extra_info.test.js +109 -0
- package/tests/legacy/generics.test.js +176 -0
- package/tests/legacy/mutation_observer.test.js +210 -0
- package/tests/legacy/relation.test.js +517 -0
- package/tests/legacy/selector.test.js +263 -0
- package/tests/legacy/slot.test.js +915 -0
- package/tests/legacy/virtual.test.js +394 -0
- package/tests/tmpl/binding_map.test.ts +208 -0
- package/tests/tmpl/event.test.ts +206 -0
- package/tests/tmpl/expression.test.ts +429 -0
- package/tests/tmpl/lvalue.test.ts +160 -0
- package/tests/tmpl/native_rendering.test.ts +155 -0
- package/tests/tmpl/structure.test.ts +998 -0
- package/tests/types/chaining.test.ts +614 -0
- package/tests/types/createElement.test.ts +82 -0
- package/tests/types/definition.test.ts +442 -0
- package/tsconfig.json +11 -0
- package/webpack.config.js +270 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
const { tmpl, domBackend, shadowBackend, composedBackend } = require('../base/env')
|
|
4
|
+
const glassEasel = require('../../src')
|
|
5
|
+
|
|
6
|
+
const componentSpace = new glassEasel.ComponentSpace()
|
|
7
|
+
componentSpace.updateComponentOptions({
|
|
8
|
+
writeFieldsToNode: true,
|
|
9
|
+
writeIdToDOM: true,
|
|
10
|
+
})
|
|
11
|
+
componentSpace.defineComponent({
|
|
12
|
+
is: '',
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const regElem = (config) => {
|
|
16
|
+
const { template, ...c } = config
|
|
17
|
+
if (template) c.template = tmpl(template)
|
|
18
|
+
return componentSpace.defineComponent(c)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const createElemInBackend = (is, backend) => {
|
|
22
|
+
const def = componentSpace.getComponent(is)
|
|
23
|
+
return glassEasel.Component.createWithContext(is || 'test', def, backend || domBackend)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var matchElementWithDom = require('../base/match').virtual
|
|
27
|
+
|
|
28
|
+
const testCases = function(testBackend){
|
|
29
|
+
var root = null
|
|
30
|
+
|
|
31
|
+
const createElem = function(is){
|
|
32
|
+
return createElemInBackend(is, testBackend)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
beforeAll(function(){
|
|
36
|
+
regElem({
|
|
37
|
+
is: 'virtual-a',
|
|
38
|
+
})
|
|
39
|
+
root = createElem('virtual-a')
|
|
40
|
+
root.$$.id = 'root'
|
|
41
|
+
var backendRoot = testBackend.getRootNode()
|
|
42
|
+
if (testBackend === shadowBackend) {
|
|
43
|
+
var placeholder = backendRoot.getShadowRoot().createElement('div')
|
|
44
|
+
backendRoot.getShadowRoot().getRootNode().appendChild(placeholder)
|
|
45
|
+
glassEasel.Element.replaceDocumentElement(root, backendRoot, placeholder)
|
|
46
|
+
} else if (testBackend === domBackend) {
|
|
47
|
+
var placeholder = testBackend.document.createElement('div')
|
|
48
|
+
backendRoot.appendChild(placeholder)
|
|
49
|
+
glassEasel.Element.replaceDocumentElement(root, backendRoot, placeholder)
|
|
50
|
+
} else {
|
|
51
|
+
var placeholder = testBackend.createElement('div')
|
|
52
|
+
backendRoot.appendChild(placeholder)
|
|
53
|
+
glassEasel.Element.replaceDocumentElement(root, backendRoot, placeholder)
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe('#appendChild', function(){
|
|
58
|
+
|
|
59
|
+
it('should convert to correct DOM appendChild (directly)', function(){
|
|
60
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
61
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
62
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
63
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
64
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
65
|
+
v1.appendChild(e2)
|
|
66
|
+
v1.appendChild(v2)
|
|
67
|
+
v2.appendChild(e3)
|
|
68
|
+
e1.appendChild(v1)
|
|
69
|
+
matchElementWithDom(e1)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should convert to correct DOM appendChild (with more convertion)', function(){
|
|
73
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
74
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
75
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
76
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
77
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
78
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
79
|
+
e1.appendChild(v1)
|
|
80
|
+
v1.appendChild(v2)
|
|
81
|
+
v1.appendChild(v3)
|
|
82
|
+
v2.appendChild(e2)
|
|
83
|
+
v3.appendChild(e3)
|
|
84
|
+
matchElementWithDom(e1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should convert to correct DOM insertBefore', function(){
|
|
88
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
89
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
90
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
91
|
+
var v1 = glassEasel.VirtualNode.create('virtual1', root.shadowRoot)
|
|
92
|
+
var v2 = glassEasel.VirtualNode.create('virtual2', root.shadowRoot)
|
|
93
|
+
var v3 = glassEasel.VirtualNode.create('virtual3', root.shadowRoot)
|
|
94
|
+
e1.appendChild(v1)
|
|
95
|
+
v1.appendChild(v2)
|
|
96
|
+
v1.appendChild(v3)
|
|
97
|
+
v3.appendChild(e3)
|
|
98
|
+
v2.appendChild(e2)
|
|
99
|
+
matchElementWithDom(e1)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('should work in a virtual root', function(){
|
|
103
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
104
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
105
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
106
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
107
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
108
|
+
v1.appendChild(e1)
|
|
109
|
+
e1.appendChild(v2)
|
|
110
|
+
v2.appendChild(e2)
|
|
111
|
+
v2.appendChild(e3)
|
|
112
|
+
matchElementWithDom(e1)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
if (testBackend === domBackend) it('should work in a native-rendered root', function(){
|
|
116
|
+
regElem({
|
|
117
|
+
is: 'virtual-node-a',
|
|
118
|
+
options: {
|
|
119
|
+
externalComponent: true,
|
|
120
|
+
},
|
|
121
|
+
template: '<div><slot></slot></div>',
|
|
122
|
+
})
|
|
123
|
+
var e1 = root.shadowRoot.createComponent('virtual-node-a')
|
|
124
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
125
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
126
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
127
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
128
|
+
v1.appendChild(e2)
|
|
129
|
+
v1.appendChild(e3)
|
|
130
|
+
e2.appendChild(v2)
|
|
131
|
+
e1.appendChild(v1)
|
|
132
|
+
matchElementWithDom(e1, e1.shadowRoot.root)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
describe('#insertBefore', function(){
|
|
138
|
+
|
|
139
|
+
it('should convert to correct DOM insertBefore (directly)', function(){
|
|
140
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
141
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
142
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
143
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
144
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
145
|
+
e1.appendChild(v1)
|
|
146
|
+
v1.appendChild(e3)
|
|
147
|
+
e1.appendChild(v1)
|
|
148
|
+
v1.appendChild(e3)
|
|
149
|
+
v2.appendChild(e2)
|
|
150
|
+
v1.insertBefore(v2, e3)
|
|
151
|
+
v1.insertBefore(v2, v2)
|
|
152
|
+
matchElementWithDom(e1)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('should convert to correct DOM insertBefore (with more convertion)', function(){
|
|
156
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
157
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
158
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
159
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
160
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
161
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
162
|
+
e1.appendChild(v1)
|
|
163
|
+
v1.appendChild(v3)
|
|
164
|
+
v2.appendChild(e2)
|
|
165
|
+
v3.appendChild(e3)
|
|
166
|
+
v1.insertBefore(v2, v3)
|
|
167
|
+
matchElementWithDom(e1)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('should convert to correct DOM appendChild', function(){
|
|
171
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
172
|
+
var e2 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
173
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
174
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
175
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
176
|
+
var v4 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
177
|
+
e1.appendChild(v1)
|
|
178
|
+
v1.appendChild(v4)
|
|
179
|
+
v1.insertBefore(v2, v4)
|
|
180
|
+
v1.insertBefore(v2, v4)
|
|
181
|
+
v2.appendChild(v3)
|
|
182
|
+
v3.insertBefore(e2)
|
|
183
|
+
matchElementWithDom(e1)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
describe('#removeChild', function(){
|
|
189
|
+
|
|
190
|
+
it('should convert to correct DOM removeChild (directly)', function(){
|
|
191
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
192
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
193
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
194
|
+
var e4 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
195
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
196
|
+
e1.appendChild(v1)
|
|
197
|
+
v1.appendChild(e2)
|
|
198
|
+
v1.appendChild(e4)
|
|
199
|
+
v1.appendChild(e3)
|
|
200
|
+
v1.removeChild(e4)
|
|
201
|
+
matchElementWithDom(e1)
|
|
202
|
+
matchElementWithDom(e4)
|
|
203
|
+
expect(e4.parentNode).toBe(null)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('should convert to correct DOM removeChild (with more convertion)', function(){
|
|
207
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
208
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
209
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
210
|
+
var e4 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
211
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
212
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
213
|
+
e1.appendChild(v1)
|
|
214
|
+
v1.appendChild(e2)
|
|
215
|
+
v1.appendChild(v2)
|
|
216
|
+
v2.appendChild(e4)
|
|
217
|
+
v1.appendChild(e3)
|
|
218
|
+
e1.removeChild(v1)
|
|
219
|
+
matchElementWithDom(e1)
|
|
220
|
+
matchElementWithDom(v1)
|
|
221
|
+
expect(v1.parentNode).toBe(null)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
describe('#replaceChild', function(){
|
|
227
|
+
|
|
228
|
+
it('should convert to correct DOM replaceChild (replacing directly at the end)', function(){
|
|
229
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
230
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
231
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
232
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
233
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
234
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
235
|
+
var v4 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
236
|
+
e1.appendChild(v1)
|
|
237
|
+
v1.appendChild(v3)
|
|
238
|
+
v1.appendChild(v4)
|
|
239
|
+
v2.appendChild(e2)
|
|
240
|
+
v3.appendChild(e3)
|
|
241
|
+
v1.replaceChild(v2, v3)
|
|
242
|
+
matchElementWithDom(e1)
|
|
243
|
+
matchElementWithDom(v3)
|
|
244
|
+
expect(v3.parentNode).toBe(null)
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('should convert to correct DOM replaceChild (replacing indirectly at the end)', function(){
|
|
248
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
249
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
250
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
251
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
252
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
253
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
254
|
+
var v4 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
255
|
+
e1.appendChild(v1)
|
|
256
|
+
v1.appendChild(v3)
|
|
257
|
+
v1.appendChild(v4)
|
|
258
|
+
v2.appendChild(e2)
|
|
259
|
+
v3.appendChild(e3)
|
|
260
|
+
v1.replaceChild(v2, v3)
|
|
261
|
+
matchElementWithDom(e1)
|
|
262
|
+
matchElementWithDom(v3)
|
|
263
|
+
expect(v3.parentNode).toBe(null)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('should convert to correct DOM replaceChild (replacing not at the end)', function(){
|
|
267
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
268
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
269
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
270
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
271
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
272
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
273
|
+
var v4 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
274
|
+
e1.appendChild(v1)
|
|
275
|
+
v1.appendChild(v3)
|
|
276
|
+
v1.appendChild(v4)
|
|
277
|
+
v2.appendChild(e2)
|
|
278
|
+
v3.appendChild(e3)
|
|
279
|
+
v4.appendChild(e3)
|
|
280
|
+
v1.replaceChild(v2, v3)
|
|
281
|
+
matchElementWithDom(e1)
|
|
282
|
+
matchElementWithDom(v3)
|
|
283
|
+
expect(v3.parentNode).toBe(null)
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
describe('#insertChildren #removeChildren', function(){
|
|
289
|
+
|
|
290
|
+
it('should able to do batch-insertion', function(){
|
|
291
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
292
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
293
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
294
|
+
var v1 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
295
|
+
var v2 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
296
|
+
var v3 = glassEasel.VirtualNode.create('virtual', root.shadowRoot)
|
|
297
|
+
v1.insertChildren([e2], 0)
|
|
298
|
+
v1.insertChildren([v2], 1)
|
|
299
|
+
v1.insertChildren([v3], 1)
|
|
300
|
+
e1.insertChildren([v1, e3], 0)
|
|
301
|
+
matchElementWithDom(e1)
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
it('should able to do batch-removal', function(){
|
|
305
|
+
var e1 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
306
|
+
var e2 = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
307
|
+
var e3 = glassEasel.TextNode.create('text', root.shadowRoot)
|
|
308
|
+
var v1 = glassEasel.VirtualNode.create('v1', root.shadowRoot)
|
|
309
|
+
var v2 = glassEasel.VirtualNode.create('v2', root.shadowRoot)
|
|
310
|
+
var v3 = glassEasel.VirtualNode.create('v3', root.shadowRoot)
|
|
311
|
+
v1.insertChildren([e2], 0)
|
|
312
|
+
v1.insertChildren([v2], 1)
|
|
313
|
+
e1.insertChildren([e3, v3, v1], 0)
|
|
314
|
+
e1.removeChildren(1, 2)
|
|
315
|
+
matchElementWithDom(e1)
|
|
316
|
+
matchElementWithDom(v3)
|
|
317
|
+
expect(v3.parentNode).toBe(null)
|
|
318
|
+
matchElementWithDom(v1)
|
|
319
|
+
expect(v1.parentNode).toBe(null)
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
describe('component virtualHost', function(){
|
|
325
|
+
|
|
326
|
+
it('should create virtualized host node', function(){
|
|
327
|
+
regElem({
|
|
328
|
+
is: 'virtual-host-a',
|
|
329
|
+
options: {
|
|
330
|
+
virtualHost: true,
|
|
331
|
+
},
|
|
332
|
+
template: '<div><slot /></div>',
|
|
333
|
+
})
|
|
334
|
+
regElem({
|
|
335
|
+
is: 'virtual-host-b',
|
|
336
|
+
options: {
|
|
337
|
+
virtualHost: true,
|
|
338
|
+
},
|
|
339
|
+
template: '<span><virtual-host-a><slot /></virtual-host-a></span><virtual-host-a></virtual-host-a>',
|
|
340
|
+
})
|
|
341
|
+
var parent = glassEasel.NativeNode.create('span', root.shadowRoot)
|
|
342
|
+
var elem = root.shadowRoot.createComponent('virtual-host-b')
|
|
343
|
+
parent.appendChild(elem)
|
|
344
|
+
matchElementWithDom(parent)
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
if (testBackend === domBackend) it('should handles tree manipulations', function(){
|
|
348
|
+
regElem({
|
|
349
|
+
is: 'virtual-host-c',
|
|
350
|
+
options: {
|
|
351
|
+
virtualHost: true,
|
|
352
|
+
},
|
|
353
|
+
template: '<slot />',
|
|
354
|
+
})
|
|
355
|
+
regElem({
|
|
356
|
+
is: 'virtual-host-d',
|
|
357
|
+
options: {
|
|
358
|
+
virtualHost: true,
|
|
359
|
+
},
|
|
360
|
+
template: '<div id="v"><span id="s"><slot /></span></div>',
|
|
361
|
+
})
|
|
362
|
+
regElem({
|
|
363
|
+
is: 'virtual-host-e',
|
|
364
|
+
template: '<virtual-host-c id="c"><virtual-host-d /></virtual-host-c><virtual-host-d id="d"><virtual-host-c /></virtual-host-d>'
|
|
365
|
+
})
|
|
366
|
+
var elem = createElem('virtual-host-e')
|
|
367
|
+
expect(elem.$$.childNodes[0]).toBe(elem.$.c.childNodes[0].$.v.$$)
|
|
368
|
+
expect(elem.$$.childNodes[1]).toBe(elem.$.d.$.v.$$)
|
|
369
|
+
matchElementWithDom(elem)
|
|
370
|
+
elem.$.d.shadowRoot.insertBefore(elem.$.d.$.s, elem.$.d.$.v)
|
|
371
|
+
expect(elem.$$.childNodes[1]).toBe(elem.$.d.$.s.$$)
|
|
372
|
+
matchElementWithDom(elem)
|
|
373
|
+
elem.$.c.replaceChild(elem.$.d, elem.$.c.childNodes[0])
|
|
374
|
+
expect(elem.$$.childNodes[0]).toBe(elem.$.d.$.s.$$)
|
|
375
|
+
expect(elem.$$.childNodes.length).toBe(2)
|
|
376
|
+
matchElementWithDom(elem)
|
|
377
|
+
elem.$.c.removeChild(elem.$.c.childNodes[0])
|
|
378
|
+
expect(elem.$$.childNodes.length).toBe(0)
|
|
379
|
+
matchElementWithDom(elem)
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
describe('VirtualNode (DOM backend)', function(){
|
|
387
|
+
testCases(domBackend)
|
|
388
|
+
})
|
|
389
|
+
describe('VirtualNode (shadow backend)', function(){
|
|
390
|
+
testCases(shadowBackend)
|
|
391
|
+
})
|
|
392
|
+
describe('VirtualNode (composed backend)', function(){
|
|
393
|
+
testCases(composedBackend)
|
|
394
|
+
})
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { tmpl, domBackend } from '../base/env'
|
|
2
|
+
import * as glassEasel from '../../src'
|
|
3
|
+
|
|
4
|
+
const domHtml = (elem: glassEasel.Element): string => {
|
|
5
|
+
const domElem = elem.getBackendElement() as unknown as Element
|
|
6
|
+
return domElem.innerHTML
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('binding map update enabled', () => {
|
|
10
|
+
test('multi-target update', () => {
|
|
11
|
+
const def = glassEasel.registerElement({
|
|
12
|
+
template: tmpl(`
|
|
13
|
+
<div class="class-a {{c}}">
|
|
14
|
+
<span id="b" data-a="{{c}}">{{c}}</span>
|
|
15
|
+
</div>
|
|
16
|
+
`),
|
|
17
|
+
data: {
|
|
18
|
+
c: 'abc',
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
const elem = glassEasel.Component.createWithContext('root', def.general(), domBackend)
|
|
22
|
+
const child = elem.getShadowRoot()!.getElementById('b')!
|
|
23
|
+
expect(domHtml(elem)).toBe('<div class="class-a abc"><span>abc</span></div>')
|
|
24
|
+
expect(child.dataset!.a).toBe('abc')
|
|
25
|
+
elem.setData({ c: 'def' })
|
|
26
|
+
expect(domHtml(elem)).toBe('<div class="class-a def"><span>def</span></div>')
|
|
27
|
+
expect(child.dataset!.a).toBe('def')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('model data path update', () => {
|
|
31
|
+
const subComp = glassEasel.registerElement({
|
|
32
|
+
template: tmpl(`
|
|
33
|
+
<div>{{propA}}</div>
|
|
34
|
+
<slot />
|
|
35
|
+
`),
|
|
36
|
+
properties: {
|
|
37
|
+
propA: Number,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
const def = glassEasel.registerElement({
|
|
41
|
+
using: {
|
|
42
|
+
comp: subComp.general(),
|
|
43
|
+
},
|
|
44
|
+
template: tmpl(`
|
|
45
|
+
<comp id="comp" model:prop-a="{{ list[index].a }}">{{ ['A', 'B', 'C'][index + 1] }}</comp>
|
|
46
|
+
`),
|
|
47
|
+
data: {
|
|
48
|
+
index: 0,
|
|
49
|
+
list: [{
|
|
50
|
+
a: 123,
|
|
51
|
+
}, {
|
|
52
|
+
a: 456,
|
|
53
|
+
}],
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
const elem = glassEasel.Component.createWithContext('root', def, domBackend)
|
|
57
|
+
const comp = elem.getShadowRoot()!.getElementById('comp') as glassEasel.GeneralComponent
|
|
58
|
+
expect(domHtml(elem)).toBe('<comp><div>123</div>B</comp>')
|
|
59
|
+
comp.setData({ propA: 789 })
|
|
60
|
+
expect(domHtml(elem)).toBe('<comp><div>789</div>B</comp>')
|
|
61
|
+
expect(elem.data.list).toEqual([{ a: 789 }, { a: 456 }])
|
|
62
|
+
elem.setData({ index: 1 })
|
|
63
|
+
expect(domHtml(elem)).toBe('<comp><div>456</div>C</comp>')
|
|
64
|
+
expect(elem.data.list).toEqual([{ a: 789 }, { a: 456 }])
|
|
65
|
+
comp.setData({ propA: 123 })
|
|
66
|
+
expect(domHtml(elem)).toBe('<comp><div>123</div>C</comp>')
|
|
67
|
+
expect(elem.data.list).toEqual([{ a: 789 }, { a: 123 }])
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('binding map update forced', () => {
|
|
72
|
+
test('mixed usage in multiple components', () => {
|
|
73
|
+
const subComp = glassEasel.registerElement({
|
|
74
|
+
properties: {
|
|
75
|
+
content: String,
|
|
76
|
+
propA: Number,
|
|
77
|
+
},
|
|
78
|
+
template: tmpl(`
|
|
79
|
+
<div>{{content}}</div>
|
|
80
|
+
`),
|
|
81
|
+
})
|
|
82
|
+
const def = glassEasel.registerElement({
|
|
83
|
+
using: {
|
|
84
|
+
'sub-comp': subComp.general(),
|
|
85
|
+
},
|
|
86
|
+
template: tmpl(`
|
|
87
|
+
<sub-comp content="{{c}}" model:prop-a="{{a}}" />
|
|
88
|
+
`, { updateMode: 'bindingMap' }),
|
|
89
|
+
data: {
|
|
90
|
+
a: 123,
|
|
91
|
+
c: 'abc',
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
const elem = glassEasel.Component.createWithContext('root', def, domBackend)
|
|
95
|
+
const child = (elem.getShadowRoot()!.childNodes[0] as glassEasel.GeneralComponent)
|
|
96
|
+
.asInstanceOf(subComp)!
|
|
97
|
+
expect(domHtml(elem)).toBe('<sub-comp><div>abc</div></sub-comp>')
|
|
98
|
+
elem.setData({ c: 'def' })
|
|
99
|
+
expect(domHtml(elem)).toBe('<sub-comp><div>def</div></sub-comp>')
|
|
100
|
+
child.setData({ propA: 456 })
|
|
101
|
+
expect(elem.data.a).toBe(456)
|
|
102
|
+
child.setData({ propA: 789 })
|
|
103
|
+
expect(elem.data.a).toBe(789)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('ignore fields with usage in if position', () => {
|
|
107
|
+
const def = glassEasel.registerElement({
|
|
108
|
+
template: tmpl(`
|
|
109
|
+
<div>{{a}}</div>
|
|
110
|
+
<div>{{b}}</div>
|
|
111
|
+
<div>{{c}}</div>
|
|
112
|
+
<div wx:if="{{b}}">{{c}}</div>
|
|
113
|
+
`, { updateMode: 'bindingMap' }),
|
|
114
|
+
data: {
|
|
115
|
+
a: 1,
|
|
116
|
+
b: 2,
|
|
117
|
+
c: 3,
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
const elem = glassEasel.Component.createWithContext('root', def.general(), domBackend)
|
|
121
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div><div>3</div><div>3</div>')
|
|
122
|
+
elem.setData({ b: 20 })
|
|
123
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div><div>3</div><div>3</div>')
|
|
124
|
+
elem.setData({ c: 30 })
|
|
125
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div><div>3</div><div>3</div>')
|
|
126
|
+
elem.setData({ a: 10 })
|
|
127
|
+
expect(domHtml(elem)).toBe('<div>10</div><div>2</div><div>3</div><div>3</div>')
|
|
128
|
+
elem.setData({ a: 100, b: 200 })
|
|
129
|
+
expect(domHtml(elem)).toBe('<div>100</div><div>2</div><div>3</div><div>3</div>')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('ignore fields with usage in for position', () => {
|
|
133
|
+
const def = glassEasel.registerElement({
|
|
134
|
+
template: tmpl(`
|
|
135
|
+
<div>{{a}}</div>
|
|
136
|
+
<div>{{b}}</div>
|
|
137
|
+
<div>{{c}}</div>
|
|
138
|
+
<div wx:for="{{[1, b]}}">{{c}}</div>
|
|
139
|
+
`, { updateMode: 'bindingMap' }),
|
|
140
|
+
data: {
|
|
141
|
+
a: 1,
|
|
142
|
+
b: 2,
|
|
143
|
+
c: 3,
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
const elem = glassEasel.Component.createWithContext('root', def.general(), domBackend)
|
|
147
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div><div>3</div><div>3</div><div>3</div>')
|
|
148
|
+
elem.setData({ b: 20 })
|
|
149
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div><div>3</div><div>3</div><div>3</div>')
|
|
150
|
+
elem.setData({ c: 30 })
|
|
151
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div><div>3</div><div>3</div><div>3</div>')
|
|
152
|
+
elem.setData({ a: 10 })
|
|
153
|
+
expect(domHtml(elem)).toBe('<div>10</div><div>2</div><div>3</div><div>3</div><div>3</div>')
|
|
154
|
+
elem.setData({ a: 100, b: 200 })
|
|
155
|
+
expect(domHtml(elem)).toBe('<div>100</div><div>2</div><div>3</div><div>3</div><div>3</div>')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('ignore fields with usage in template position', () => {
|
|
159
|
+
const def = glassEasel.registerElement({
|
|
160
|
+
template: tmpl(`
|
|
161
|
+
<template name="child">
|
|
162
|
+
<div>{{c}}</div>
|
|
163
|
+
</template>
|
|
164
|
+
<div>{{a}}</div>
|
|
165
|
+
<div>{{b}}</div>
|
|
166
|
+
<div>{{c}}</div>
|
|
167
|
+
<template is="{{b}}" data="{{ {c} }}"></template>
|
|
168
|
+
`, { updateMode: 'bindingMap' }),
|
|
169
|
+
data: {
|
|
170
|
+
a: 1,
|
|
171
|
+
b: 'child',
|
|
172
|
+
c: 3,
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
const elem = glassEasel.Component.createWithContext('root', def.general(), domBackend)
|
|
176
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>child</div><div>3</div><div>3</div>')
|
|
177
|
+
elem.setData({ b: 20 })
|
|
178
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>child</div><div>3</div><div>3</div>')
|
|
179
|
+
elem.setData({ c: 30 })
|
|
180
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>child</div><div>3</div><div>3</div>')
|
|
181
|
+
elem.setData({ a: 10 })
|
|
182
|
+
expect(domHtml(elem)).toBe('<div>10</div><div>child</div><div>3</div><div>3</div>')
|
|
183
|
+
elem.setData({ a: 100, b: 200 })
|
|
184
|
+
expect(domHtml(elem)).toBe('<div>100</div><div>child</div><div>3</div><div>3</div>')
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('ignore fields with usage in slot position', () => {
|
|
188
|
+
const def = glassEasel.registerElement({
|
|
189
|
+
template: tmpl(`
|
|
190
|
+
<div>{{a}}</div>
|
|
191
|
+
<div>{{b}}</div>
|
|
192
|
+
<slot name="{{b}}"></slot>
|
|
193
|
+
`, { updateMode: 'bindingMap' }),
|
|
194
|
+
data: {
|
|
195
|
+
a: 1,
|
|
196
|
+
b: 2,
|
|
197
|
+
},
|
|
198
|
+
})
|
|
199
|
+
const elem = glassEasel.Component.createWithContext('root', def.general(), domBackend)
|
|
200
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div>')
|
|
201
|
+
elem.setData({ b: 20 })
|
|
202
|
+
expect(domHtml(elem)).toBe('<div>1</div><div>2</div>')
|
|
203
|
+
elem.setData({ a: 10 })
|
|
204
|
+
expect(domHtml(elem)).toBe('<div>10</div><div>2</div>')
|
|
205
|
+
elem.setData({ a: 100, b: 200 })
|
|
206
|
+
expect(domHtml(elem)).toBe('<div>100</div><div>2</div>')
|
|
207
|
+
})
|
|
208
|
+
})
|