Skip to content

Commit b03fab6

Browse files
committed
init
1 parent 13495c9 commit b03fab6

File tree

10 files changed

+56
-190
lines changed

10 files changed

+56
-190
lines changed

doc/en/essentials/api/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function App() {
2929
return (
3030
<>
3131
<button onClick={add}>add</button>
32-
<p>{count}</p>
32+
<p>{count.value}</p>
3333
</>
3434
);
3535
}
@@ -51,8 +51,8 @@ function App() {
5151
return (
5252
<>
5353
<button onClick={add}>add</button>
54-
<p>{count}</p>
55-
<p>{double}</p>
54+
<p>{count.value}</p>
55+
<p>{double.value}</p>
5656
</>
5757
);
5858
}
@@ -75,7 +75,7 @@ function App() {
7575
return (
7676
<>
7777
<button onClick={change}>change</button>
78-
<p>{name}</p>
78+
<p>{name.value}</p>
7979
</>
8080
);
8181
}
@@ -100,8 +100,8 @@ function App() {
100100
return (
101101
<>
102102
<button onClick={change}>change</button>
103-
<p>{name}</p>
104-
<p>{surname}</p>
103+
<p>{name.value}</p>
104+
<p>{surname.value}</p>
105105
</>
106106
);
107107
}
@@ -129,8 +129,8 @@ function App() {
129129
return (
130130
<>
131131
<button onClick={change}>change</button>
132-
<p>{name}</p>
133-
<p>{surname}</p>
132+
<p>{name.value}</p>
133+
<p>{surname.value}</p>
134134
</>
135135
);
136136
}
@@ -154,7 +154,7 @@ function HandleArr() {
154154
<>
155155
<button onClick={push}>push</button>
156156
<ul>
157-
{arr.map((item) => (
157+
{arr.value.map((item) => (
158158
<li key={item}>{item}</li>
159159
))}
160160
</ul>
@@ -178,7 +178,7 @@ function HandleObj() {
178178
return (
179179
<>
180180
<button onClick={change}>change</button>
181-
<p>{obj.name}</p>
181+
<p>{obj.value.name}</p>
182182
</>
183183
);
184184
}
@@ -243,7 +243,7 @@ This API is only used in the unbuilt version.
243243
```js
244244
function App() {
245245
const count = 0;
246-
return () => html`<p>${count}</p>`;
246+
return () => html`<p>${count.value}</p>`;
247247
}
248248
```
249249

doc/en/essentials/usage/index.md

Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Mettle allows developers to declaratively bind the DOM to the underlying instanc
1010
function App() {
1111
const msg = signal('Hello');
1212

13-
return <h1>{msg}</h1>;
13+
return <h1>{msg.value}</h1>;
1414
}
1515
```
1616

@@ -20,7 +20,7 @@ function App() {
2020
function App() {
2121
const msg = signal('Hello');
2222

23-
return <input type='text' value={msg} />;
23+
return <input type='text' value={msg.value} />;
2424
}
2525
```
2626

@@ -39,7 +39,7 @@ function App() {
3939
return (
4040
<>
4141
<button onClick={useShow}>show</button>
42-
<div>{isShow ? <p>Mettle.js</p> : <null></null>}</div>
42+
<div>{isShow.value ? <p>Mettle.js</p> : <null></null>}</div>
4343
</>
4444
);
4545
}
@@ -63,7 +63,7 @@ function HandleArr() {
6363
<>
6464
<button onClick={push}>push</button>
6565
<ul>
66-
{arr.map((item) => (
66+
{arr.value.map((item) => (
6767
<li key={item}>{item}</li>
6868
))}
6969
</ul>
@@ -106,7 +106,7 @@ function MyComponent() {
106106

107107
return (
108108
<>
109-
<p>{count}</p>
109+
<p>{count.value}</p>
110110
<button onClick={add}>MyComponent</button>
111111
</>
112112
);
@@ -121,7 +121,7 @@ function App() {
121121

122122
return (
123123
<>
124-
<p>{count}</p>
124+
<p>{count.value}</p>
125125
<button onClick={add}>App</button>
126126
<MyComponent />
127127
</>
@@ -220,8 +220,8 @@ function App() {
220220
return (
221221
<>
222222
<button onClick={add}>Add</button>
223-
<h1 $once>{count}</h1>
224-
<h2>{count}</h2>
223+
<h1 $once>{count.value}</h1>
224+
<h2>{count.value}</h2>
225225
</>
226226
);
227227
}
@@ -263,10 +263,10 @@ function App({ memo }) {
263263
return (
264264
<>
265265
<ul onClick={handle}>
266-
{arr.map((todo) => (
266+
{arr.value.map((todo) => (
267267
<li
268-
$memo={[todo.id == selected, symbol1]}
269-
class={todo.id == selected ? 'danger' : ''}
268+
$memo={[todo.id == selected.value, symbol1]}
269+
class={todo.id == selected.value ? 'danger' : ''}
270270
key={todo.id}
271271
data-id={todo.id}
272272
>
@@ -279,7 +279,7 @@ function App({ memo }) {
279279
}
280280
```
281281

282-
Because the element hit by the `$memo` tag will not update its child elements by default, if you want to update it, explicitly define the third item of the array as `true`, such as `$memo={[todo.id == selected, symbol1,true]}`.
282+
Because the element hit by the `$memo` tag will not update its child elements by default, if you want to update it, explicitly define the third item of the array as `true`, such as `$memo={[todo.id == selected.value, symbol1,true]}`.
283283

284284
## Built-in Tags
285285

@@ -298,7 +298,7 @@ function App() {
298298
return (
299299
<>
300300
<button onClick={useShow}>show</button>
301-
<div>{isShow ? <p>Mettle.js</p> : <null></null>}</div>
301+
<div>{isShow.value ? <p>Mettle.js</p> : <null></null>}</div>
302302
</>
303303
);
304304
}
@@ -324,71 +324,3 @@ function App() {
324324
);
325325
}
326326
```
327-
328-
## Auto-unwrapping
329-
330-
When `Signals` is accessed in a `JSX` template, it is automatically unwrapped, so you no longer need to write `.value` for it in the `JSX` template.
331-
332-
```jsx
333-
function App() {
334-
const count = signal(0);
335-
336-
function add() {
337-
count.value++;
338-
}
339-
340-
return (
341-
<>
342-
<button onClick={add}>add</button>
343-
<p>{count}</p>
344-
</>
345-
);
346-
}
347-
```
348-
349-
However, please note that auto-unwrapping is not possible in the following cases.
350-
351-
- Component communication
352-
353-
```jsx
354-
function Child({ props }) {
355-
return <h4>{props.count.value}</h4>;
356-
}
357-
358-
function App() {
359-
const count = signal(2);
360-
361-
function increment() {
362-
count.value++;
363-
}
364-
365-
return (
366-
<>
367-
<button onClick={increment}>add</button>
368-
<Child count={count}></Child>
369-
</>
370-
);
371-
}
372-
```
373-
374-
- Deep unpacking is not supported
375-
376-
```jsx
377-
const obj = signal({
378-
name: 'hello',
379-
obj1: {
380-
age: 10,
381-
show:true
382-
},
383-
});
384-
385-
<p>{obj.name}</p> // Support
386-
387-
<p>{obj.obj1.age}</p> // Not supported
388-
```
389-
390-
- Attribute expressions are not supported.
391-
392-
```jsx
393-
<tr class={item.id === selected.value ? 'danger' : ''}>
394-
```

doc/en/guide/install/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ The advantages of no builds come with tradeoffs:
6666

6767
- Unable to use `JSX` syntax
6868
- Component functions must `return` a template function
69-
- Signal mechanisms cannot be automatically unwrapped; `.value` must be used manually
7069

7170
:::
7271

doc/en/guide/started/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Let's develop a simple counter application using just one function.
3131
```jsx
3232
function Counter() {
3333
const count = signal(0);
34+
const add = () => count.value++;
3435

35-
return <button onClick={() => count.value++}>{count}</button>;
36+
return <button onClick={add}>{count.value}</button>;
3637
}
3738
```

doc/en/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ hero:
2323
```jsx
2424
function Counter() {
2525
const count = signal(0);
26+
const add = () => count.value++;
2627

27-
return <button onClick={() => count.value++}>{count}</button>;
28+
return <button onClick={add}>{count.value}</button>;
2829
}
2930
```

doc/zh/essentials/api/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function App() {
2929
return (
3030
<>
3131
<button onClick={add}>add</button>
32-
<p>{count}</p>
32+
<p>{count.value}</p>
3333
</>
3434
);
3535
}
@@ -51,8 +51,8 @@ function App() {
5151
return (
5252
<>
5353
<button onClick={add}>add</button>
54-
<p>{count}</p>
55-
<p>{double}</p>
54+
<p>{count.value}</p>
55+
<p>{double.value}</p>
5656
</>
5757
);
5858
}
@@ -75,7 +75,7 @@ function App() {
7575
return (
7676
<>
7777
<button onClick={change}>change</button>
78-
<p>{name}</p>
78+
<p>{name.value}</p>
7979
</>
8080
);
8181
}
@@ -100,8 +100,8 @@ function App() {
100100
return (
101101
<>
102102
<button onClick={change}>change</button>
103-
<p>{name}</p>
104-
<p>{surname}</p>
103+
<p>{name.value}</p>
104+
<p>{surname.value}</p>
105105
</>
106106
);
107107
}
@@ -129,8 +129,8 @@ function App() {
129129
return (
130130
<>
131131
<button onClick={change}>change</button>
132-
<p>{name}</p>
133-
<p>{surname}</p>
132+
<p>{name.value}</p>
133+
<p>{surname.value}</p>
134134
</>
135135
);
136136
}
@@ -154,7 +154,7 @@ function HandleArr() {
154154
<>
155155
<button onClick={push}>push</button>
156156
<ul>
157-
{arr.map((item) => (
157+
{arr.value.map((item) => (
158158
<li key={item}>{item}</li>
159159
))}
160160
</ul>
@@ -178,7 +178,7 @@ function HandleObj() {
178178
return (
179179
<>
180180
<button onClick={change}>change</button>
181-
<p>{obj.name}</p>
181+
<p>{obj.value.name}</p>
182182
</>
183183
);
184184
}
@@ -243,7 +243,7 @@ function App() {
243243
```js
244244
function App() {
245245
const count = 0;
246-
return () => html`<p>${count}</p>`;
246+
return () => html`<p>${count.value}</p>`;
247247
}
248248
```
249249

0 commit comments

Comments
 (0)