dothtml 4.8.6 → 5.0.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/{jest.config.js → jest.config.ts} +19 -16
- package/lib/arg-callback-obj.d.ts +29 -0
- package/lib/built-in-components/nav-link.d.ts +8 -0
- package/lib/built-in-components/router.d.ts +57 -0
- package/lib/component.d.ts +73 -0
- package/lib/dot-component-legacy.d.ts +0 -0
- package/lib/dot-document.d.ts +0 -0
- package/lib/dot-util.d.ts +13 -0
- package/lib/dot.d.ts +5 -0
- package/lib/dothtml.d.ts +21 -0
- package/lib/dothtml.js +2 -0
- package/lib/dothtml.js.LICENSE.txt +1 -0
- package/lib/err.d.ts +2 -0
- package/lib/event-bus.d.ts +10 -0
- package/lib/i-dot.d.ts +674 -0
- package/lib/i-dotcss.d.ts +821 -0
- package/lib/node-polyfill.d.ts +2 -0
- package/lib/observable-array.d.ts +49 -0
- package/lib/style-builder.d.ts +3 -0
- package/package.json +11 -5
- package/readme.md +3 -2
- package/src/{arg-callback-obj.js → arg-callback-obj.ts} +18 -6
- package/src/built-in-components/nav-link.ts +21 -0
- package/src/built-in-components/router.ts +315 -0
- package/src/component.ts +369 -0
- package/src/dot-component-legacy.ts +79 -0
- package/src/dot-document.ts +0 -0
- package/src/dot-util.ts +33 -0
- package/src/dot.ts +1147 -0
- package/src/dothtml.ts +33 -0
- package/src/err.ts +22 -0
- package/src/event-bus.ts +39 -0
- package/src/i-dot.ts +787 -0
- package/src/i-dotcss.ts +911 -0
- package/src/node-polyfill.ts +11 -0
- package/src/{observable-array.js → observable-array.ts} +10 -5
- package/src/{style-builder.js → style-builder.ts} +219 -183
- package/tsconfig.json +99 -0
- package/unittests/advanced-bindings.test.ts +421 -0
- package/unittests/{array-evaluation.test.js → array-evaluation.test.ts} +1 -1
- package/unittests/{basic-functionality.test.js → basic-functionality.test.ts} +14 -10
- package/unittests/class-binding.test.ts +227 -0
- package/unittests/component-decorator.-.ts +14 -0
- package/unittests/components-data.test.ts +153 -0
- package/unittests/components.test.ts +257 -0
- package/unittests/computed.test.ts +35 -0
- package/unittests/{core.js → core.ts} +5 -2
- package/unittests/element-and-attribute-coverage.test.ts +472 -0
- package/unittests/hooks.test.ts +67 -0
- package/unittests/immutable-if.test.ts +19 -0
- package/unittests/input-bindings.test.ts +166 -0
- package/unittests/integration.test.ts +5 -0
- package/unittests/{iterations.test.js → iterations.test.ts} +5 -5
- package/unittests/logic.test.ts +18 -0
- package/unittests/refs.test.ts +36 -0
- package/unittests/routing.-.ts +56 -0
- package/unittests/{scopes.test.js → scopes.test.ts} +5 -5
- package/unittests/special-tags.test.ts +39 -0
- package/unittests/styles.test.ts +9 -0
- package/unittests/{testpage.js → testpage.ts} +2 -0
- package/unittests/{wait.test.js → wait.test.ts} +8 -5
- package/webpack.config.js +13 -1
- package/lib/dothtml.min.js +0 -1
- package/src/component.js +0 -305
- package/src/err.js +0 -20
- package/src/event-bus.js +0 -40
- package/src/index.js +0 -1453
- package/src/util.js +0 -13
- package/unittests/advanced-bindings.test.js +0 -386
- package/unittests/class-binding.test.js +0 -53
- package/unittests/components-data.test.js +0 -97
- package/unittests/components.test.js +0 -151
- package/unittests/computed.test.js +0 -36
- package/unittests/hooks.test.js +0 -57
- package/unittests/immutable-if.test.js +0 -15
- package/unittests/input-bindings.test.js +0 -155
- package/unittests/integration.test.js +0 -6
- package/unittests/logic.test.js +0 -18
- package/unittests/routing.-.js +0 -56
- package/unittests/special-tags.test.js +0 -32
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import addTest from "./core";
|
|
2
|
+
import dot from "../src/dothtml";
|
|
3
|
+
import Component from "../src/component";
|
|
4
|
+
|
|
5
|
+
addTest("Basic immutable class binding.", function(){
|
|
6
|
+
return dot.div().class({
|
|
7
|
+
"foo": true,
|
|
8
|
+
"bar": false,
|
|
9
|
+
"xyz": true
|
|
10
|
+
})
|
|
11
|
+
}, "<div class=\"foo xyz\"></div>");
|
|
12
|
+
|
|
13
|
+
addTest("Class binding to a component property.", function(){
|
|
14
|
+
class C extends Component{
|
|
15
|
+
constructor(v){
|
|
16
|
+
super();
|
|
17
|
+
this.props.prop = v;
|
|
18
|
+
}
|
|
19
|
+
props = {
|
|
20
|
+
prop: false
|
|
21
|
+
};
|
|
22
|
+
builder(){
|
|
23
|
+
return dot.div().class({
|
|
24
|
+
"foo": ()=>this.props.prop,
|
|
25
|
+
"bar": ()=>!this.props.prop,
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
ready(){
|
|
29
|
+
this.props.prop = !this.props.prop;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return dot.h(new C(false)).h(new C(true));
|
|
34
|
+
|
|
35
|
+
}, "<div class=\"foo\"></div><div class=\"bar\"></div>");
|
|
36
|
+
|
|
37
|
+
addTest("Class binding to a component property with a style.", function(){
|
|
38
|
+
class C extends Component{
|
|
39
|
+
constructor(v){
|
|
40
|
+
super();
|
|
41
|
+
this.props.prop = v;
|
|
42
|
+
}
|
|
43
|
+
props = {
|
|
44
|
+
prop: false
|
|
45
|
+
};
|
|
46
|
+
builder(){
|
|
47
|
+
return dot.div().class({
|
|
48
|
+
"foo": ()=>this.props.prop,
|
|
49
|
+
"bar": ()=>!this.props.prop,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
ready(){
|
|
53
|
+
this.props.prop = !this.props.prop;
|
|
54
|
+
}
|
|
55
|
+
style(css){
|
|
56
|
+
css("div").backgroundColor("white");
|
|
57
|
+
css(".foo").color("red");
|
|
58
|
+
css(".bar").color("blue");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return dot.h(new C(false)).h(new C(true));
|
|
63
|
+
|
|
64
|
+
}, "<div class=\"foo\" style=\"background-color: rgb(255, 255, 255); color: rgb(255, 0, 0);\"></div><div class=\"bar\" style=\"background-color: rgb(255, 255, 255); color: rgb(0, 0, 255);\"></div>");
|
|
65
|
+
|
|
66
|
+
addTest("Remove styles applied by a class.", function(){
|
|
67
|
+
class C extends Component{
|
|
68
|
+
constructor(v){
|
|
69
|
+
super();
|
|
70
|
+
this.props.prop = v;
|
|
71
|
+
}
|
|
72
|
+
props = {
|
|
73
|
+
prop: false
|
|
74
|
+
};
|
|
75
|
+
builder(){
|
|
76
|
+
return dot.div().class({
|
|
77
|
+
"foo": ()=>this.props.prop,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
ready(){
|
|
81
|
+
this.props.prop = !this.props.prop;
|
|
82
|
+
}
|
|
83
|
+
style(css){
|
|
84
|
+
css(".foo").color("red");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return dot.h(new C(true));
|
|
89
|
+
|
|
90
|
+
}, "<div class=\"\"></div>");
|
|
91
|
+
addTest("Remove styles applied by a nested class.", function(){
|
|
92
|
+
class C extends Component{
|
|
93
|
+
constructor(v){
|
|
94
|
+
super();
|
|
95
|
+
this.props.prop = v;
|
|
96
|
+
}
|
|
97
|
+
props = {
|
|
98
|
+
prop: false
|
|
99
|
+
};
|
|
100
|
+
builder(){
|
|
101
|
+
return dot.div(
|
|
102
|
+
dot.div().class({
|
|
103
|
+
"foo": ()=>this.props.prop,
|
|
104
|
+
})
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
ready(){
|
|
108
|
+
this.props.prop = !this.props.prop;
|
|
109
|
+
}
|
|
110
|
+
style(css){
|
|
111
|
+
css(".foo").color("red");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return dot.h(new C(true));
|
|
116
|
+
|
|
117
|
+
}, "<div><div class=\"\"></div></div>");
|
|
118
|
+
|
|
119
|
+
addTest("Remove only dynamic styles applied by a class.", function(){
|
|
120
|
+
class C extends Component{
|
|
121
|
+
constructor(v){
|
|
122
|
+
super();
|
|
123
|
+
this.props.prop = v;
|
|
124
|
+
}
|
|
125
|
+
props = {
|
|
126
|
+
prop: false
|
|
127
|
+
};
|
|
128
|
+
builder(){
|
|
129
|
+
return dot.div().class({
|
|
130
|
+
"foo": ()=>this.props.prop,
|
|
131
|
+
}).style(dot.css.backgroundColor("blue"))
|
|
132
|
+
}
|
|
133
|
+
ready(){
|
|
134
|
+
this.props.prop = !this.props.prop;
|
|
135
|
+
}
|
|
136
|
+
style(css){
|
|
137
|
+
css(".foo").color("red");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return dot.h(new C(true));
|
|
142
|
+
|
|
143
|
+
}, "<div class=\"\" data-dot-static-styles=\"background-color:rgb(0, 0, 255);\" style=\"background-color:rgb(0, 0, 255);\"></div>");
|
|
144
|
+
|
|
145
|
+
addTest("Remove only dynamic styles applied by a nested class.", function(){
|
|
146
|
+
class C extends Component{
|
|
147
|
+
constructor(v){
|
|
148
|
+
super();
|
|
149
|
+
this.props.prop = v;
|
|
150
|
+
}
|
|
151
|
+
props = {
|
|
152
|
+
prop: false
|
|
153
|
+
};
|
|
154
|
+
builder(){
|
|
155
|
+
return dot.div(
|
|
156
|
+
dot.div().class({
|
|
157
|
+
"foo": ()=>this.props.prop,
|
|
158
|
+
}).style(dot.css.backgroundColor("blue"))
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
ready(){
|
|
162
|
+
this.props.prop = !this.props.prop;
|
|
163
|
+
}
|
|
164
|
+
style(css){
|
|
165
|
+
css(".foo").color("red");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return dot.h(new C(true));
|
|
170
|
+
|
|
171
|
+
}, "<div><div class=\"\" data-dot-static-styles=\"background-color:rgb(0, 0, 255);\" style=\"background-color:rgb(0, 0, 255);\"></div></div>");
|
|
172
|
+
|
|
173
|
+
addTest("Dynamic styles contribute to static styles.", function(){
|
|
174
|
+
class C extends Component{
|
|
175
|
+
constructor(v){
|
|
176
|
+
super();
|
|
177
|
+
this.props.prop = v;
|
|
178
|
+
}
|
|
179
|
+
props = {
|
|
180
|
+
prop: false
|
|
181
|
+
};
|
|
182
|
+
builder(){
|
|
183
|
+
return dot.div().class({
|
|
184
|
+
"foo": ()=>this.props.prop,
|
|
185
|
+
}).style(dot.css.backgroundColor("blue"))
|
|
186
|
+
}
|
|
187
|
+
ready(){
|
|
188
|
+
this.props.prop = !this.props.prop;
|
|
189
|
+
}
|
|
190
|
+
style(css){
|
|
191
|
+
css(".foo").color("red");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return dot.h(new C(false));
|
|
196
|
+
|
|
197
|
+
}, "<div class=\"foo\" data-dot-static-styles=\"background-color:rgb(0, 0, 255);\" style=\"background-color: rgb(0, 0, 255); color: rgb(255, 0, 0);\"></div>");
|
|
198
|
+
|
|
199
|
+
addTest("Class based on computed field.", function(){
|
|
200
|
+
class C extends Component{
|
|
201
|
+
constructor(){
|
|
202
|
+
super();
|
|
203
|
+
}
|
|
204
|
+
props = {
|
|
205
|
+
prop: []
|
|
206
|
+
};
|
|
207
|
+
builder(){
|
|
208
|
+
return dot.div().class({
|
|
209
|
+
"foo": ()=>this.isFoo,
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
get isFoo(){
|
|
213
|
+
let value = this.props.prop.length > 0;
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
ready(){
|
|
218
|
+
this.props.prop.push(1);
|
|
219
|
+
}
|
|
220
|
+
style(css){
|
|
221
|
+
css(".foo").color("red");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return dot.h(new C());
|
|
226
|
+
|
|
227
|
+
}, "<div class=\"foo\" style=\"color: rgb(255, 0, 0);\"></div>");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// import addTest from "./core";
|
|
2
|
+
// import dot from "../src/dothtml";
|
|
3
|
+
// import Component from "../src/component";
|
|
4
|
+
// import { IDotElement, IDotGenericElement } from "i-dot";
|
|
5
|
+
|
|
6
|
+
// TBD...
|
|
7
|
+
|
|
8
|
+
// @component
|
|
9
|
+
// class TestComponent implements Component{
|
|
10
|
+
// builder(...args: any[]): IDotElement<IDotGenericElement> {
|
|
11
|
+
// throw new Error("Method not implemented.");
|
|
12
|
+
// }
|
|
13
|
+
|
|
14
|
+
// }
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import addTest from "./core";
|
|
2
|
+
import dot from "../src/dothtml";
|
|
3
|
+
import Component from "../src/component";
|
|
4
|
+
|
|
5
|
+
// For testing the passing of data into and out of components via properties and events, respectively.
|
|
6
|
+
|
|
7
|
+
addTest("Prop default value.", function(){
|
|
8
|
+
class MyComp extends Component{
|
|
9
|
+
props = {
|
|
10
|
+
myProp: 1
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
builder(){
|
|
14
|
+
var ret = dot.span(()=>this.props.myProp);
|
|
15
|
+
return ret;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var myComp = new MyComp();
|
|
20
|
+
return dot.h(myComp);
|
|
21
|
+
}, "<span>1</span>");
|
|
22
|
+
|
|
23
|
+
addTest("Pass value into component.", function(){
|
|
24
|
+
class MyComp extends Component{
|
|
25
|
+
props = {
|
|
26
|
+
myProp: 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(){
|
|
30
|
+
super();
|
|
31
|
+
this.props.myProp = 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
builder(){
|
|
35
|
+
var ret = dot.span(()=>this.props.myProp);
|
|
36
|
+
return ret;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var myComp = new MyComp();
|
|
41
|
+
myComp.props.myProp = 2;
|
|
42
|
+
return dot.h(myComp);
|
|
43
|
+
}, "<span>2</span>");
|
|
44
|
+
|
|
45
|
+
// TODO
|
|
46
|
+
// addTest("Binding value into component.", function(){
|
|
47
|
+
// const MyComp = dot.component({
|
|
48
|
+
// builder(){
|
|
49
|
+
// this.myProp = 1;
|
|
50
|
+
// var ret = dot.span(()=>this.myProp);
|
|
51
|
+
// return ret;
|
|
52
|
+
// },
|
|
53
|
+
// props:["myProp"]
|
|
54
|
+
// });
|
|
55
|
+
|
|
56
|
+
// var myComp = MyComp();
|
|
57
|
+
// myComp.myProp = 2;
|
|
58
|
+
// return dot.h(myComp);
|
|
59
|
+
// }, "<span>2</span>");
|
|
60
|
+
|
|
61
|
+
addTest("Raise event from component.", function(){
|
|
62
|
+
class MyComp extends Component{
|
|
63
|
+
props = {
|
|
64
|
+
myProp: 0
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// events:["go"],
|
|
68
|
+
events = {
|
|
69
|
+
go: (number)=>undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
constructor(){
|
|
73
|
+
super();
|
|
74
|
+
this.props.myProp = 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
builder(){
|
|
78
|
+
var ret = dot.span(()=>this.props.myProp);
|
|
79
|
+
return ret;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
ready(){
|
|
83
|
+
this.events.go(5);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var myComp = new MyComp();
|
|
88
|
+
myComp.props.myProp = 2;
|
|
89
|
+
myComp.on("go", x=>{
|
|
90
|
+
myComp.props.myProp=x
|
|
91
|
+
});
|
|
92
|
+
// Experimented with this syntax.
|
|
93
|
+
// myComp.on(myComp.events.go, ()=>{})
|
|
94
|
+
return dot.h(myComp);
|
|
95
|
+
}, "<span>5</span>");
|
|
96
|
+
|
|
97
|
+
addTest("Raise 2 events from component.", function(){
|
|
98
|
+
class MyComp extends Component{
|
|
99
|
+
constructor(){
|
|
100
|
+
super();
|
|
101
|
+
this.props.myProp = 1;
|
|
102
|
+
}
|
|
103
|
+
builder(){
|
|
104
|
+
var ret = dot.span(()=>this.props.myProp);
|
|
105
|
+
return ret;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
props = {
|
|
109
|
+
myProp: 0
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
events = {
|
|
113
|
+
go2: (number) => undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
ready(){
|
|
117
|
+
this.events.go2("3");
|
|
118
|
+
this.events.go2("4");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var myComp = new MyComp();
|
|
123
|
+
myComp.props.myProp = 2;
|
|
124
|
+
myComp.on("go2", x=>myComp.props.myProp+=x);
|
|
125
|
+
return dot.h(myComp);
|
|
126
|
+
}, "<span>234</span>");
|
|
127
|
+
|
|
128
|
+
addTest("Call a method from outside a component.", function(){
|
|
129
|
+
class MyComp extends Component{
|
|
130
|
+
constructor(){
|
|
131
|
+
super();
|
|
132
|
+
this.props.myProp = 1;
|
|
133
|
+
}
|
|
134
|
+
builder(){
|
|
135
|
+
var ret = dot.span(()=>this.props.myProp);
|
|
136
|
+
return ret;
|
|
137
|
+
}
|
|
138
|
+
props={
|
|
139
|
+
myProp: 0
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
go(v){
|
|
143
|
+
this.props.myProp = v;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
var myComp = new MyComp();
|
|
150
|
+
myComp.props.myProp = 2;
|
|
151
|
+
myComp.go(5);
|
|
152
|
+
return dot.h(myComp);
|
|
153
|
+
}, "<span>5</span>");
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import addTest from "./core";
|
|
2
|
+
import dot from "../src/dothtml";
|
|
3
|
+
import Component from "../src/component";
|
|
4
|
+
|
|
5
|
+
class comp_legacy extends dot.Component{
|
|
6
|
+
|
|
7
|
+
builder(){
|
|
8
|
+
return dot.div(dot.div(1));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class comp_std extends dot.Component{
|
|
12
|
+
builder(){
|
|
13
|
+
return dot.div(dot.div(1));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
class comp_ready extends dot.Component{
|
|
17
|
+
builder(){
|
|
18
|
+
return dot.div(dot.div(1));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ready(){
|
|
22
|
+
this.$el.innerHTML = "OKAY";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class comp_el_one_el extends dot.Component{
|
|
27
|
+
builder(){
|
|
28
|
+
return dot.div("abc");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class comp_el_two_el extends dot.Component{
|
|
33
|
+
builder(){
|
|
34
|
+
return dot.div("abc").div("abc");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
abstract class ParameterizedComponent extends dot.Component{
|
|
39
|
+
params: Array<any>;
|
|
40
|
+
constructor(...params: Array<any>){
|
|
41
|
+
super();
|
|
42
|
+
this.params = params;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// class comp_el_deferred_el extends dot.Component{
|
|
47
|
+
// builder(){
|
|
48
|
+
// return dot.div("abc").wait(function(){}, 1000);
|
|
49
|
+
// }
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
// Testing methods:
|
|
53
|
+
// TODO: passing callMethod in like this will soon be deprecated.
|
|
54
|
+
class comp_methods_basic extends dot.Component{
|
|
55
|
+
callMethod: boolean;
|
|
56
|
+
constructor(callMethod: boolean){
|
|
57
|
+
super();
|
|
58
|
+
this.callMethod = callMethod;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
builder(){
|
|
62
|
+
return dot.div("123");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
ready(){
|
|
66
|
+
if(this.callMethod) this.setVal("abc");
|
|
67
|
+
}
|
|
68
|
+
setVal(val){
|
|
69
|
+
dot(this.$el).empty().t(val);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Scoped classes
|
|
74
|
+
dot.resetScopeClass();
|
|
75
|
+
class comp_scoped_class extends dot.Component{
|
|
76
|
+
builder(){
|
|
77
|
+
return dot.div(dot.div().class("test2")).class("test1")
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
class comp_scoped_class_2 extends dot.Component{
|
|
81
|
+
builder(){ return dot.div(dot.div().class("test2")).class("test1") }
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
// Nameless components (exports):
|
|
86
|
+
//addTest("Nameless component.", function(){ var comp = dot.component({builder: function(c){return dot.p(c)} }); return dot.div(comp(":)")) }, "<div><p>:)</p></div>");
|
|
87
|
+
// This behavior was deprecated.
|
|
88
|
+
//addTest("Nameless component as a dot function.", function(){ var comp = dot.component({builder: function(c){return dot.p(c)} }); return comp(":)") }, "<p>:)</p>" );
|
|
89
|
+
|
|
90
|
+
// Named components (extend dot):
|
|
91
|
+
addTest("Std params component.", function(){return dot.h(new comp_std())}, "<div><div>1</div></div>");
|
|
92
|
+
// addTest("Std params component, nested.", function(){return dot.div(2).comp_std().div(3)}, "<div>2</div><div><div>1</div></div><div>3</div>");
|
|
93
|
+
// addTest("Std prams component beside markup.", function(){return dot.h(2).comp_std().h(3)}, "2<div><div>1</div></div>3");
|
|
94
|
+
addTest("Legacy params component.", function(){return dot.h(new comp_legacy())}, "<div><div>1</div></div>");
|
|
95
|
+
addTest("Component w/ ready method.", function(){return dot.h(new comp_ready())}, "<div>OKAY</div>");
|
|
96
|
+
// addTest("Text component.", function(){return dot.h("a").comp_text().h("b")}, "a1b");
|
|
97
|
+
//addTest("Text component w/ ready method.", function(){return dot.h("a").comp_textreplace().h("b")}, "a2b");
|
|
98
|
+
|
|
99
|
+
// $el
|
|
100
|
+
// addTest("Undefined $el.", function(){try{return new comp_el_undefined_el()}catch(e){return dot.span(e)}}, "<span>Component 'comp_el_undefined_el' must return exactly one child node.</span>");
|
|
101
|
+
// addTest("Zero $el.", function(){try{return new comp_el_zero_el()}catch(e){return dot.span(e)}}, "<span>Component 'comp_el_zero_el' must return exactly one child node.</span>");
|
|
102
|
+
addTest("One $el.", function(){return dot.h( new comp_el_one_el())}, "<div>abc</div>");
|
|
103
|
+
addTest("Two $el.", function(){try{return dot.h( new comp_el_two_el())}catch(e){return dot.span(e)}}, "<span>Component 'comp_el_two_el' must return exactly one child node.</span>");
|
|
104
|
+
// addTest("Deferred $el.", function(){try{return new comp_el_deferred_el()}catch(e){return dot.span(e)}}, "<span>Component 'comp_el_deferred_el' must return exactly one child node.</span>");
|
|
105
|
+
// addTest("One $el.", function(){return new comp_el_text_zero_el()}, "abc");
|
|
106
|
+
// addTest("One $el.", function(){return new comp_el_text_one_el()}, "<div>abc</div>");
|
|
107
|
+
// addTest("Undefined $el.", function(){try{return new comp_el_text_two_el()}catch(e){return dot.span(e)}}, "<span>Component 'comp_el_text_two_el' must return exactly one child node.</span>");
|
|
108
|
+
|
|
109
|
+
// methods
|
|
110
|
+
addTest("Instantiate comp w/ method.", function(){return dot.h(new comp_methods_basic(false))}, "<div>123</div>");
|
|
111
|
+
addTest("Method gets called in ready function.", function(){return dot.h(new comp_methods_basic(true))}, "<div>abc</div>"); // TODO: this functionality will soon be removed in favor of params.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
// TODO: setup this test and get it working.
|
|
115
|
+
// addTest("Computed property w/ updated dependency.", function(){
|
|
116
|
+
// let comp = dot.component({
|
|
117
|
+
// builder: function(firstName,lastName){this.firstName = firstName; this.lastName = lastName; return dot.p(this.fullName.toUpperCase())},
|
|
118
|
+
// computed: {
|
|
119
|
+
// fullName: function(){
|
|
120
|
+
// console.log("GETTING COMPUTED PROP!");
|
|
121
|
+
// return this.firstName + " " + this.lastName;
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
// });
|
|
125
|
+
// return dot.h(comp("J","S"));
|
|
126
|
+
// },"<p>J S</p>");
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
// Events // TODO: get these working.
|
|
130
|
+
// addTest(
|
|
131
|
+
// "Named events work.",
|
|
132
|
+
// function(){
|
|
133
|
+
// let comp = dot.component({
|
|
134
|
+
// builder: function(a,b){this.a = a; this.b = b; return dot.p(a+b)},
|
|
135
|
+
// events: ["sumReady"],
|
|
136
|
+
// methods: {trigger: function(){this.sumReady(this.a+this.b);}},
|
|
137
|
+
// });
|
|
138
|
+
// let sumResult = 0;
|
|
139
|
+
// let c = comp(1,2).sumReady(function(v){ console.log("CALLING EVENT!!");sumResult = v});
|
|
140
|
+
// c.trigger();
|
|
141
|
+
// return dot.p(sumResult);
|
|
142
|
+
// },
|
|
143
|
+
// "<p>3</p>"
|
|
144
|
+
// );
|
|
145
|
+
|
|
146
|
+
// Scoped classes
|
|
147
|
+
// TODO: the tests work in browser, but seem to happen out of order in jest...
|
|
148
|
+
// addTest("Component class scope.", function(){return dot.comp_scoped_class()}, "<div class=\"dot-10000-test1\"><div class=\"dot-10000-test2\"></div></div>");
|
|
149
|
+
// addTest("Component class scope reuse.", function(){return dot.comp_scoped_class()}, "<div class=\"dot-10000-test1\"><div class=\"dot-10000-test2\"></div></div>");
|
|
150
|
+
// addTest("Component class scope alt.", function(){return dot.comp_scoped_class_2()}, "<div class=\"dot-10001-test1\"><div class=\"dot-10001-test2\"></div></div>");
|
|
151
|
+
|
|
152
|
+
// Styles
|
|
153
|
+
addTest("Set style directly", function(){var ret = dot.p(":)").style("width:100px;"); return ret;}, "<p style=\"width:100px;\">:)</p>");
|
|
154
|
+
addTest("Set style via dotcss", function(){var ret = dot.p(":)").style(dot.css.width(100)); return ret;}, "<p style=\"width:100px;\">:)</p>");
|
|
155
|
+
|
|
156
|
+
addTest("Styled component.", function(){
|
|
157
|
+
class comp extends ParameterizedComponent{
|
|
158
|
+
builder(){
|
|
159
|
+
return dot.p(this.params[0]);
|
|
160
|
+
}
|
|
161
|
+
style(css){
|
|
162
|
+
css("p").width(100);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return dot.h(new comp(":)")) }, "<p style=\"width: 100px;\">:)</p>"
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
addTest("Advanced styled component.", function(){
|
|
169
|
+
class comp extends ParameterizedComponent{
|
|
170
|
+
builder(){
|
|
171
|
+
return dot.p(this.params[0])
|
|
172
|
+
}
|
|
173
|
+
style(css){
|
|
174
|
+
css("p").width(100);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return dot.h(new comp(":)")).h(new comp(":)"))
|
|
178
|
+
}, "<p style=\"width: 100px;\">:)</p><p style=\"width: 100px;\">:)</p>" );
|
|
179
|
+
|
|
180
|
+
addTest("Component with multiple styles.", function(){
|
|
181
|
+
class comp extends ParameterizedComponent{
|
|
182
|
+
builder(){
|
|
183
|
+
return dot.p(this.params[0])
|
|
184
|
+
}
|
|
185
|
+
style(css){
|
|
186
|
+
css("p").width(this.params[1]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return dot.h(new comp(":)", 200)).h(new comp(":)", 300))
|
|
190
|
+
}, "<p style=\"width: 200px;\">:)</p><p style=\"width: 300px;\">:)</p>" );
|
|
191
|
+
|
|
192
|
+
addTest("Component with class styles.", function(){
|
|
193
|
+
class comp extends ParameterizedComponent{
|
|
194
|
+
builder(){
|
|
195
|
+
return dot.div(
|
|
196
|
+
dot.div(this.params[0])
|
|
197
|
+
.div("w").class("w")
|
|
198
|
+
.div("ok").class("h")
|
|
199
|
+
).class("w");
|
|
200
|
+
}
|
|
201
|
+
style(css){
|
|
202
|
+
css(".w").width(this.params[1]);css(".h").width(this.params[2]);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return dot.h(new comp(":)", 200, 400)).h(new comp(":)", 300, 500)).div().class("h");
|
|
206
|
+
}, "<div class=\"w\" style=\"width: 200px;\"><div>:)</div><div class=\"w\" style=\"width: 200px;\">w</div><div class=\"h\" style=\"width: 400px;\">ok</div></div><div class=\"w\" style=\"width: 300px;\"><div>:)</div><div class=\"w\" style=\"width: 300px;\">w</div><div class=\"h\" style=\"width: 500px;\">ok</div></div><div class=h></div>" );
|
|
207
|
+
|
|
208
|
+
addTest("Styles should not apply to nested elements.", function(){
|
|
209
|
+
class CompOuter extends ParameterizedComponent{
|
|
210
|
+
builder(){
|
|
211
|
+
return dot.div(this.params[0]);
|
|
212
|
+
}
|
|
213
|
+
style(css){
|
|
214
|
+
css("div").backgroundColor("#FF0000");
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
class CompInner extends dot.Component{
|
|
219
|
+
builder(){
|
|
220
|
+
return dot.div("FOOBAR");
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
return dot.h(new CompOuter(new CompInner()))
|
|
225
|
+
}, "<div style=\"background-color: rgb(255, 0, 0);\"><div>FOOBAR</div></div>");
|
|
226
|
+
|
|
227
|
+
addTest("Styles should not apply to nested elements 2.", function(){
|
|
228
|
+
class CompOuter extends ParameterizedComponent{
|
|
229
|
+
builder(){
|
|
230
|
+
return dot.div(this.params[0]);
|
|
231
|
+
}
|
|
232
|
+
style(css){
|
|
233
|
+
css("div").backgroundColor("#FF0000");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
class CompInner extends dot.Component{
|
|
238
|
+
builder(){return dot.div(dot.div("FOOBAR"));}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return dot.h(new CompOuter(new CompInner()))
|
|
242
|
+
}, "<div style=\"background-color: rgb(255, 0, 0);\"><div><div>FOOBAR</div></div></div>");
|
|
243
|
+
|
|
244
|
+
// Event Bus
|
|
245
|
+
|
|
246
|
+
addTest("Event bus basic usage.", function(){
|
|
247
|
+
class comp1 extends dot.Component{
|
|
248
|
+
builder(){
|
|
249
|
+
var t = this;
|
|
250
|
+
dot.bus.on("change", function(v){t.$el.innerHTML = v});
|
|
251
|
+
return dot.p();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
var ret = dot.h(new comp1()); dot.bus.emit("change", "hello");
|
|
256
|
+
return ret;
|
|
257
|
+
}, "<p>hello</p>");
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import addTest from "./core";
|
|
2
|
+
import dot from "../src/dothtml";
|
|
3
|
+
import Component from "../src/component";
|
|
4
|
+
|
|
5
|
+
class Comp extends Component{
|
|
6
|
+
props={
|
|
7
|
+
firstName: "",
|
|
8
|
+
lastName: ""
|
|
9
|
+
}
|
|
10
|
+
constructor(firstName, lastName){
|
|
11
|
+
super();
|
|
12
|
+
this.props.firstName = firstName;
|
|
13
|
+
this.props.lastName = lastName;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
builder(){
|
|
17
|
+
return dot.p(()=>this.fullName.toUpperCase())
|
|
18
|
+
}
|
|
19
|
+
get fullName(){
|
|
20
|
+
return (this.props.firstName||"notset") + " " + (this.props.lastName||"notset");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
addTest("Computed property.", function(){
|
|
24
|
+
|
|
25
|
+
return dot.h( new Comp("J","S")).h(new Comp("1","2"));
|
|
26
|
+
},"<p>J S</p><p>1 2</p>");
|
|
27
|
+
|
|
28
|
+
addTest("Computed property w/ prop dependency.", function(){
|
|
29
|
+
|
|
30
|
+
var instance = new Comp("x", "y");
|
|
31
|
+
var ret = dot.h(instance);
|
|
32
|
+
instance.props.firstName = "j";
|
|
33
|
+
instance.props.lastName = "s";
|
|
34
|
+
return ret;
|
|
35
|
+
},"<p>J S</p>");
|