You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/en/changeLog/index.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# Change Log
2
2
3
-
## v1.1.2 (Latest)
3
+
## v1.7.0 (Latest)
4
+
5
+
- Introducing the `Signals` mechanism, which automatically updates components and the UI when state changes, ensuring the most efficient operation possible.
The first parameter is the root component, which is required. The second parameter is used to mount the root component. Receive a "container" parameter, which can be an actual DOM element or a CSS selector string.
7
+
The first parameter is the root component, required. The second parameter is used to mount the root component. Receives a "container" parameter, which can be an actual DOM element or a CSS selector string.
8
8
9
9
```jsx
10
10
functionApp() {
11
-
return() =><h1>Hello</h1>;
11
+
return<h1>Hello</h1>;
12
12
}
13
13
14
14
createApp(<App />, '#app');
15
15
```
16
16
17
-
## setData
17
+
## signal
18
18
19
-
Modifying page data is best performed at the end of the logic.
19
+
Creates a new signal with the given parameters as the initial value.
20
20
21
-
The first parameter is the context, which is required in the outer scope but not in the inner scope. In the inner scope, it can be referenced directly in the function component.
21
+
```jsx
22
+
functionApp() {
23
+
constcount=signal(0);
24
+
25
+
functionadd() {
26
+
count.value++;
27
+
}
28
+
29
+
return (
30
+
<fragment>
31
+
<button onClick={add}>add</button>
32
+
<p>{count}</p>
33
+
</fragment>
34
+
);
35
+
}
36
+
```
37
+
38
+
## computed
22
39
23
-
**Internal scope:**
40
+
Creates a new signal that is computed based on the value of another signal. The returned computed signal is read-only and its value is automatically updated when any signal accessed within the callback function changes.
24
41
25
42
```jsx
26
-
functionApp({ setData }) {
27
-
let count =0;
43
+
functionApp() {
44
+
constcount=signal(0);
45
+
constdouble=computed(() =>count.value*2);
28
46
29
47
functionadd() {
30
-
count++;
31
-
setData();
48
+
count.value++;
32
49
}
33
50
34
-
return () => (
51
+
return (
35
52
<fragment>
36
-
<button onClick={add}>Add</button>
37
-
<h1>{count}</h1>
53
+
<button onClick={add}>add</button>
54
+
<p>{count}</p>
55
+
<p>{double}</p>
38
56
</fragment>
39
57
);
40
58
}
41
59
```
42
60
43
-
**External scope:**
61
+
## effect
62
+
63
+
To run arbitrary code based on a signal change, use `effect(fn)`. Similar to `computed`, `effect` keeps track of which signals are accessed and reruns its callback when those signals change. Unlike `computed`, `effect()` does not return a signal.
The `batch(fn)` function can be used to combine multiple value updates into a single "commit" at the end of the provided callback.
87
+
88
+
```jsx
89
+
functionApp() {
90
+
constname=signal('hello');
91
+
constsurname=signal('dog');
92
+
93
+
functionchange() {
94
+
batch(() => {
95
+
name.value='Hello';
96
+
surname.value='cat';
97
+
});
98
+
}
49
99
50
-
functionadd() {
51
-
count++;
52
-
setData(App);
100
+
return (
101
+
<fragment>
102
+
<button onClick={change}>change</button>
103
+
<p>{name}</p>
104
+
<p>{surname}</p>
105
+
</fragment>
106
+
);
53
107
}
108
+
```
109
+
110
+
## untracked
54
111
112
+
`untracked(fn)` can be used to access the values of multiple signals without subscribing to them.
113
+
114
+
```jsx
55
115
functionApp() {
56
-
return () => (
116
+
constname=signal('hello');
117
+
constsurname=signal('dog');
118
+
119
+
effect(() => {
120
+
untracked(() => {
121
+
console.log(`${name.value}${surname.value}`);
122
+
});
123
+
});
124
+
125
+
functionchange() {
126
+
surname.value='cat';
127
+
}
128
+
129
+
return (
130
+
<fragment>
131
+
<button onClick={change}>change</button>
132
+
<p>{name}</p>
133
+
<p>{surname}</p>
134
+
</fragment>
135
+
);
136
+
}
137
+
```
138
+
139
+
## produce
140
+
141
+
Provides responsive management of complex objects.
142
+
143
+
```jsx
144
+
functionhandleArr() {
145
+
constarr=signal([1]);
146
+
147
+
functionpush() {
148
+
arr.value=produce(arr.value, (item) => {
149
+
item.push(newDate().getTime());
150
+
});
151
+
}
152
+
153
+
return (
57
154
<fragment>
58
-
<button onClick={add}>Add</button>
59
-
<h1>{count}</h1>
155
+
<button onClick={push}>push</button>
156
+
<ul>
157
+
{arr.value.map((item) => (
158
+
<li key={item}>{item}</li>
159
+
))}
160
+
</ul>
60
161
</fragment>
61
162
);
62
163
}
63
164
```
64
165
65
-
The second parameter is optional and is of type `Symbol`. It is used with the built-in property `$memo` to indicate updated data.
166
+
```jsx
167
+
functionhandleObj() {
168
+
constobj=signal({
169
+
name:'hello',
170
+
});
171
+
172
+
functionchange() {
173
+
obj.value=produce(obj.value, (item) => {
174
+
item.name='world';
175
+
});
176
+
}
177
+
178
+
return (
179
+
<fragment>
180
+
<button onClick={change}>change</button>
181
+
<p>{obj.value.name}</p>
182
+
</fragment>
183
+
);
184
+
}
185
+
```
66
186
67
187
## onMounted
68
188
69
-
Register a callback function to be executed after the component is mounted.
189
+
Registers a callback function to be executed after the component is mounted.
70
190
71
191
```jsx
72
192
functionApp() {
73
193
onMounted(() => {
74
194
console.log('onMounted', 'about');
75
195
});
76
196
77
-
return () => (
78
-
<fragment>
79
-
<h1>About</h1>
80
-
</fragment>
81
-
);
197
+
return<h1>About</h1>
82
198
}
83
199
```
84
200
@@ -92,11 +208,7 @@ function App() {
92
208
console.log('onUnmounted', 'about');
93
209
});
94
210
95
-
return () => (
96
-
<fragment>
97
-
<h1>About</h1>
98
-
</fragment>
99
-
);
211
+
return<h1>About</h1>
100
212
}
101
213
```
102
214
@@ -112,30 +224,30 @@ function App() {
112
224
console.log('domInfo', domInfo.get(h1));
113
225
}
114
226
115
-
return () => (
116
-
<fragment>
117
-
<h1 $ref={h1} onClick={getDomInfo}>
118
-
Hello
119
-
</h1>
120
-
</fragment>
227
+
return (
228
+
<h1 $ref={h1} onClick={getDomInfo}>
229
+
Hello
230
+
</h1>
121
231
);
122
232
}
123
233
```
124
234
125
235
## html
126
236
127
-
` html`` ` is a tag function. The syntax of the tag function is to directly follow the function name with a template string. For example, you can write HTML tags directly in the template string.
237
+
` html`` ` is a tag function. The syntax for a tag function is to directly follow the function name with a template string. For example, you can write HTML tags directly in the template string.
128
238
129
-
In the JSX syntax environment, this API will not be used.
239
+
::: warning
240
+
This API is only used in the unbuilt version.
241
+
:::
130
242
131
243
```js
132
244
functionApp() {
133
-
let count =0;
245
+
constcount=0;
134
246
return () =>html`<p>${count}</p>`;
135
247
}
136
248
```
137
249
138
250
::: tip
139
-
If you are using the VSCode editor, you can go to the store to download the [es6-string-html](https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html)plug-in,
140
-
This plugin enables HTML template string highlighting.
251
+
If you're using the VS Code editor, you can download the [es6-string-html](https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html)plugin from the store.
0 commit comments