Skip to content

Commit ebf2c03

Browse files
committed
init
1 parent 8123df0 commit ebf2c03

15 files changed

Lines changed: 120 additions & 174 deletions

File tree

doc/.vitepress/cache/deps/_metadata.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"hash": "34652ad1",
3-
"configHash": "09913fa0",
2+
"hash": "18e6f8c7",
3+
"configHash": "891b3535",
44
"lockfileHash": "a0e730cd",
5-
"browserHash": "4004c618",
5+
"browserHash": "46dd3ae7",
66
"optimized": {
77
"vue": {
88
"src": "../../../../node_modules/.pnpm/vue@3.5.13/node_modules/vue/dist/vue.runtime.esm-bundler.js",
99
"file": "vue.js",
10-
"fileHash": "c1ab87de",
10+
"fileHash": "e2656c28",
1111
"needsInterop": false
1212
},
1313
"vitepress > @vue/devtools-api": {
1414
"src": "../../../../node_modules/.pnpm/@vue+devtools-api@7.6.4/node_modules/@vue/devtools-api/dist/index.js",
1515
"file": "vitepress___@vue_devtools-api.js",
16-
"fileHash": "f58f77c0",
16+
"fileHash": "7d8b133b",
1717
"needsInterop": false
1818
},
1919
"vitepress > @vueuse/core": {
2020
"src": "../../../../node_modules/.pnpm/@vueuse+core@11.2.0_vue@3.5.13/node_modules/@vueuse/core/index.mjs",
2121
"file": "vitepress___@vueuse_core.js",
22-
"fileHash": "40c46c9f",
22+
"fileHash": "6191dd33",
2323
"needsInterop": false
2424
}
2525
},

doc/en/changeLog/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change Log
22

3-
## v1.1.0 (Latest)
3+
## v1.1.2 (Latest)
44

55
- Optimize the underlying code structure.
66

doc/en/essentials/api/index.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ createApp(<App />, '#app');
1616

1717
## setData
1818

19-
Modify page data.
19+
Modifying page data is best performed at the end of the logic.
2020

21-
The first parameter is a function, which must be passed. Execute the callback function to modify the associated page data.
22-
The second parameter is the context, which must be passed in the outer scope and not in the inner scope.
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.
2322

2423
**Internal scope:**
2524

@@ -28,9 +27,8 @@ function App({ setData }) {
2827
let count = 0;
2928

3029
function add() {
31-
setData(() => {
32-
count++;
33-
});
30+
count++;
31+
setData();
3432
}
3533

3634
return () => (
@@ -50,9 +48,8 @@ import { setData } from 'mettle';
5048
let count = 0;
5149

5250
function add() {
53-
setData(() => {
54-
count++;
55-
}, App);
51+
count++;
52+
setData(App);
5653
}
5754

5855
function App() {
@@ -65,7 +62,7 @@ function App() {
6562
}
6663
```
6764

68-
The third parameter is optional. Its type is `Symbol` and is used with the built-in attribute `$memo` to indicate updated data.
65+
The second parameter is optional and is of type `Symbol`. It is used with the built-in property `$memo` to indicate updated data.
6966

7067
## onMounted
7168

doc/en/essentials/example/index.md

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
function TwoWay({ setData }) {
77
let value = '';
88
function useInput(e) {
9-
setData(() => {
10-
value = e.target.value;
11-
});
9+
value = e.target.value;
10+
setData();
1211
}
1312

1413
return () => (
@@ -29,9 +28,8 @@ function Son({ setData, content }) {
2928
};
3029

3130
content.getList = function (val) {
32-
setData(() => {
33-
props.list = val;
34-
});
31+
props.list = val;
32+
setData();
3533
};
3634

3735
return () => (
@@ -91,9 +89,8 @@ function Father({ setData }) {
9189
let msg = '';
9290

9391
Son.getMsg = function (val) {
94-
setData(() => {
95-
msg = val;
96-
});
92+
msg = val;
93+
setData();
9794
};
9895

9996
return () => (
@@ -122,14 +119,13 @@ function Timer({ setData }) {
122119

123120
let handle = null;
124121
function update() {
125-
setData(() => {
126-
data.elapsed = performance.now() - lastTime;
127-
if (data.elapsed >= data.duration) {
128-
cancelAnimationFrame(handle);
129-
} else {
130-
handle = requestAnimationFrame(update);
131-
}
132-
});
122+
data.elapsed = performance.now() - lastTime;
123+
if (data.elapsed >= data.duration) {
124+
cancelAnimationFrame(handle);
125+
} else {
126+
handle = requestAnimationFrame(update);
127+
}
128+
setData();
133129
}
134130

135131
update();
@@ -160,7 +156,7 @@ function Son({ content, setData }) {
160156
}
161157

162158
content.update = function () {
163-
setData(() => {});
159+
setData();
164160
};
165161

166162
return () => (
@@ -173,18 +169,16 @@ function Son({ content, setData }) {
173169

174170
function Store({ setData }) {
175171
function getUserInfo() {
176-
setData(() => {
177-
store.dispatch('fetchUser').then(() => {
178-
console.log(store.state.user); // { name: 'John Doe', age: 30 }
179-
});
172+
store.dispatch('fetchUser').then(() => {
173+
console.log(store.state.user); // { name: 'John Doe', age: 30 }
180174
});
175+
setData();
181176
}
182177

183178
function add() {
184-
setData(() => {
185-
store.commit('increment');
186-
Son.update();
187-
});
179+
store.commit('increment');
180+
Son.update();
181+
setData();
188182
}
189183

190184
return () => (
@@ -287,14 +281,12 @@ function Toast({ setData,content }) {
287281

288282
content.show = (val) => {
289283
clearTimeout(timer);
290-
setData(() => {
291-
isShow = true;
292-
msg = val;
293-
});
284+
isShow = true;
285+
msg = val;
286+
setData();
294287
timer = setTimeout(() => {
295-
setData(() => {
296-
isShow = false;
297-
});
288+
isShow = false;
289+
setData();
298290
}, 2000);
299291
};
300292

doc/en/essentials/usage/index.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ function App({ setData }) {
7272
};
7373

7474
function useShow() {
75-
setData(() => {
76-
state.isShow = !state.isShow;
77-
});
75+
state.isShow = !state.isShow;
76+
setData();
7877
}
7978
return () => (
8079
<fragment>
@@ -96,9 +95,8 @@ function App({ setData }) {
9695
};
9796

9897
function usePush() {
99-
setData(() => {
100-
state.arr.push(3);
101-
});
98+
state.arr.push(3);
99+
setData();
102100
}
103101
return () => (
104102
<fragment>
@@ -149,9 +147,8 @@ function MyComponent({ setData }) {
149147
let count = 0;
150148

151149
function add() {
152-
setData(() => {
153-
count++;
154-
});
150+
count++;
151+
setData();
155152
}
156153

157154
return () => (
@@ -166,9 +163,8 @@ function App({setData}) {
166163
let count = 0;
167164

168165
const add = () => {
169-
setData(() => {
170-
count++;
171-
});
166+
count++;
167+
setData();
172168
};
173169

174170
return () => (
@@ -256,9 +252,8 @@ function App({ setData }) {
256252
let count = 0;
257253

258254
function add() {
259-
setData(() => {
260-
count++;
261-
});
255+
count++;
256+
setData();
262257
}
263258

264259
return () => (
@@ -299,13 +294,8 @@ function App({ setData }) {
299294
function handle(event) {
300295
const el = event.target;
301296
const id = Number(el.dataset.id);
302-
setData(
303-
() => {
304-
selected = id;
305-
},
306-
null,
307-
symbol1
308-
);
297+
selected = id;
298+
setData(null,symbol1);
309299
return false;
310300
}
311301

@@ -343,9 +333,8 @@ function App({setData}) {
343333
};
344334

345335
function useShow() {
346-
setData(() => {
347-
state.isShow = !state.isShow;
348-
});
336+
state.isShow = !state.isShow;
337+
setData();
349338
}
350339
return () => (
351340
<fragment>

doc/en/guide/install/index.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ If you open the above index.html directly in the browser, you will find that it
1919
let count = 0;
2020
2121
function add() {
22-
setData(() => {
23-
count++;
24-
});
22+
count++;
23+
setData();
2524
}
2625
return () => html`<h1 onClick=${add}>${count}</h1>`;
2726
}
@@ -45,9 +44,8 @@ All top-level APIs of this version are exposed as properties on the global Mettl
4544
let count = 0;
4645
4746
function add() {
48-
setData(() => {
49-
count++;
50-
});
47+
count++;
48+
setData();
5149
}
5250
return () => html`<h1 onClick=${add}>${count}</h1>`;
5351
}

doc/en/guide/started/index.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ All top-level APIs in this version are exposed as properties on the global Mettl
4444
let count = 0;
4545
4646
function add() {
47-
setData(() => {
48-
count++;
49-
});
47+
count++;
48+
setData();
5049
}
5150
return () => html`<h1 onClick=${add}>${count}</h1>`;
5251
}
@@ -79,9 +78,8 @@ Most modern browsers already support ES modules, so we can use Mettle with CDN a
7978
let count = 0;
8079
8180
function add() {
82-
setData(() => {
83-
count++;
84-
});
81+
count++;
82+
setData();
8583
}
8684
return () => html`<h1 onClick=${add}>${count}</h1>`;
8785
}

doc/en/tool/mettleRouter/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ export default function Home({ setData }) {
3030
}
3131

3232
function useChange() {
33-
setData(() => {
34-
state.msg = 'world';
35-
state.count++;
36-
state.arr.unshift(state.count);
37-
});
33+
state.msg = 'world';
34+
state.count++;
35+
state.arr.unshift(state.count);
36+
setData();
3837
}
3938

4039
return () => (

doc/zh/changeLog/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 更新日志
22

3-
## v1.1.0 (Latest)
3+
## v1.1.2 (Latest)
44

55
- 优化底层代码结构。
66

0 commit comments

Comments
 (0)