-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathtodo.js
144 lines (137 loc) · 3.67 KB
/
todo.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var todo = {
'css': null,
'exports': {
onBeforeMount(props, state) {
// initial state
this.state = {
items: props.items,
text: ''
};
},
edit(e) {
// update only the text state
this.update({
text: e.target.value
});
},
add(e) {
e.preventDefault();
if (this.state.text) {
this.update({
items: [...this.state.items, // add a new item
{
title: this.state.text
}],
text: ''
});
}
},
toggle(item) {
item.done = !item.done; // trigger a component update
this.update();
}
},
'template': function (template, expressionTypes, bindingTypes, getComponent) {
return template('<h3 expr0="expr0"> </h3><ul><li expr1="expr1"></li></ul><form expr4="expr4"><input expr5="expr5"/><button expr6="expr6"> </button></form>', [{
'redundantAttribute': 'expr0',
'selector': '[expr0]',
'expressions': [{
'type': expressionTypes.TEXT,
'childNodeIndex': 0,
'evaluate': function (_scope) {
return _scope.props.title;
}
}]
}, {
'type': bindingTypes.EACH,
'getKey': null,
'condition': null,
'template': template('<label expr2="expr2"><input expr3="expr3" type="checkbox"/> </label>', [{
'expressions': [{
'type': expressionTypes.ATTRIBUTE,
'name': 'hidden',
'evaluate': function (_scope) {
return _scope.item.hidden;
}
}]
}, {
'redundantAttribute': 'expr2',
'selector': '[expr2]',
'expressions': [{
'type': expressionTypes.TEXT,
'childNodeIndex': 1,
'evaluate': function (_scope) {
return [_scope.item.title].join('');
}
}, {
'type': expressionTypes.ATTRIBUTE,
'name': 'class',
'evaluate': function (_scope) {
return _scope.item.done ? 'completed' : null;
}
}]
}, {
'redundantAttribute': 'expr3',
'selector': '[expr3]',
'expressions': [{
'type': expressionTypes.ATTRIBUTE,
'name': 'checked',
'evaluate': function (_scope) {
return _scope.item.done;
}
}, {
'type': expressionTypes.EVENT,
'name': 'onclick',
'evaluate': function (_scope) {
return () => _scope.toggle(_scope.item);
}
}]
}]),
'redundantAttribute': 'expr1',
'selector': '[expr1]',
'itemName': 'item',
'indexName': null,
'evaluate': function (_scope) {
return _scope.state.items;
}
}, {
'redundantAttribute': 'expr4',
'selector': '[expr4]',
'expressions': [{
'type': expressionTypes.EVENT,
'name': 'onsubmit',
'evaluate': function (_scope) {
return _scope.add;
}
}]
}, {
'redundantAttribute': 'expr5',
'selector': '[expr5]',
'expressions': [{
'type': expressionTypes.EVENT,
'name': 'onkeyup',
'evaluate': function (_scope) {
return _scope.edit;
}
}]
}, {
'redundantAttribute': 'expr6',
'selector': '[expr6]',
'expressions': [{
'type': expressionTypes.TEXT,
'childNodeIndex': 0,
'evaluate': function (_scope) {
return ['Add #', _scope.state.items.length + 1].join('');
}
}, {
'type': expressionTypes.ATTRIBUTE,
'name': 'disabled',
'evaluate': function (_scope) {
return !_scope.state.text;
}
}]
}]);
},
'name': 'todo'
};
export default todo;