Skip to content

Commit fb4d9a1

Browse files
LittleSoundsxzz
andauthored
feat: renderWatch / renderEffect (#86)
* refactor: use baseWatch to drive watchAPI * feat: basic implementation of renderWatch and effectId * chore: remove effect id * chore: export and simplify types * test: render watch * chore: add todo comment * fix: sync code changes according to the review in PR #82 * fix: enum values conflict * chore: rename * feat: change watchEffect to renderEffect in compiler-vapor * chore: update --------- Co-authored-by: 三咲智子 Kevin Deng <[email protected]>
1 parent bdf28de commit fb4d9a1

File tree

15 files changed

+369
-505
lines changed

15 files changed

+369
-505
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`compile > bindings 1`] = `
4-
"import { template as _template, children as _children, createTextNode as _createTextNode, insert as _insert, watchEffect as _watchEffect, setText as _setText } from 'vue/vapor';
4+
"import { template as _template, children as _children, createTextNode as _createTextNode, insert as _insert, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
55
66
export function render(_ctx) {
77
const t0 = _template("<div>count is <!>.</div>")
88
const n0 = t0()
99
const { 0: [n3, { 1: [n2],}],} = _children(n0)
1010
const n1 = _createTextNode(_ctx.count)
1111
_insert(n1, n3, n2)
12-
_watchEffect(() => {
12+
_renderEffect(() => {
1313
_setText(n1, undefined, _ctx.count)
1414
})
1515
return n0
@@ -121,45 +121,45 @@ export function render(_ctx) {
121121
`;
122122

123123
exports[`compile > directives > v-pre > self-closing v-pre 1`] = `
124-
"import { template as _template, children as _children, createTextNode as _createTextNode, append as _append, watchEffect as _watchEffect, setText as _setText, setAttr as _setAttr } from 'vue/vapor';
124+
"import { template as _template, children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setAttr as _setAttr } from 'vue/vapor';
125125
126126
export function render(_ctx) {
127127
const t0 = _template("<div></div><div><Comp></Comp></div>")
128128
const n0 = t0()
129129
const { 1: [n2],} = _children(n0)
130130
const n1 = _createTextNode(_ctx.bar)
131131
_append(n2, n1)
132-
_watchEffect(() => {
132+
_renderEffect(() => {
133133
_setText(n1, undefined, _ctx.bar)
134134
})
135-
_watchEffect(() => {
135+
_renderEffect(() => {
136136
_setAttr(n2, "id", undefined, _ctx.foo)
137137
})
138138
return n0
139139
}"
140140
`;
141141

142142
exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
143-
"import { template as _template, children as _children, createTextNode as _createTextNode, append as _append, watchEffect as _watchEffect, setText as _setText, setAttr as _setAttr } from 'vue/vapor';
143+
"import { template as _template, children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setAttr as _setAttr } from 'vue/vapor';
144144
145145
export function render(_ctx) {
146146
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>")
147147
const n0 = t0()
148148
const { 1: [n2],} = _children(n0)
149149
const n1 = _createTextNode(_ctx.bar)
150150
_append(n2, n1)
151-
_watchEffect(() => {
151+
_renderEffect(() => {
152152
_setText(n1, undefined, _ctx.bar)
153153
})
154-
_watchEffect(() => {
154+
_renderEffect(() => {
155155
_setAttr(n2, "id", undefined, _ctx.foo)
156156
})
157157
return n0
158158
}"
159159
`;
160160

161161
exports[`compile > dynamic root 1`] = `
162-
"import { fragment as _fragment, createTextNode as _createTextNode, append as _append, watchEffect as _watchEffect, setText as _setText } from 'vue/vapor';
162+
"import { fragment as _fragment, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
163163
164164
export function render(_ctx) {
165165
const t0 = _fragment()
@@ -168,18 +168,18 @@ export function render(_ctx) {
168168
const n1 = _createTextNode(1)
169169
const n2 = _createTextNode(2)
170170
_append(n0, n1, n2)
171-
_watchEffect(() => {
171+
_renderEffect(() => {
172172
_setText(n1, undefined, 1)
173173
})
174-
_watchEffect(() => {
174+
_renderEffect(() => {
175175
_setText(n2, undefined, 2)
176176
})
177177
return n0
178178
}"
179179
`;
180180

181181
exports[`compile > dynamic root nodes and interpolation 1`] = `
182-
"import { template as _template, children as _children, createTextNode as _createTextNode, prepend as _prepend, insert as _insert, append as _append, on as _on, watchEffect as _watchEffect, setText as _setText, setAttr as _setAttr } from 'vue/vapor';
182+
"import { template as _template, children as _children, createTextNode as _createTextNode, prepend as _prepend, insert as _insert, append as _append, on as _on, renderEffect as _renderEffect, setText as _setText, setAttr as _setAttr } from 'vue/vapor';
183183
184184
export function render(_ctx) {
185185
const t0 = _template("<button>foo<!>foo</button>")
@@ -192,7 +192,7 @@ export function render(_ctx) {
192192
_insert(n2, n4, n5)
193193
_append(n4, n3)
194194
_on(n4, "click", (...args) => (_ctx.handleClick && _ctx.handleClick(...args)))
195-
_watchEffect(() => {
195+
_renderEffect(() => {
196196
_setText(n1, undefined, _ctx.count)
197197
_setText(n2, undefined, _ctx.count)
198198
_setText(n3, undefined, _ctx.count)
@@ -207,7 +207,7 @@ exports[`compile > expression parsing > interpolation 1`] = `
207207
const t0 = _fragment()
208208
209209
const n0 = t0()
210-
_watchEffect(() => {
210+
_renderEffect(() => {
211211
_setText(n0, undefined, a + b.value)
212212
})
213213
return n0
@@ -219,7 +219,7 @@ exports[`compile > expression parsing > v-bind 1`] = `
219219
const t0 = _template("<div></div>")
220220
const n0 = t0()
221221
const { 0: [n1],} = _children(n0)
222-
_watchEffect(() => {
222+
_renderEffect(() => {
223223
_setAttr(n1, key.value+1, undefined, _unref(foo)[key.value+1]())
224224
})
225225
return n0
@@ -237,7 +237,7 @@ export function render(_ctx) {
237237
`;
238238

239239
exports[`compile > static + dynamic root 1`] = `
240-
"import { template as _template, children as _children, createTextNode as _createTextNode, prepend as _prepend, insert as _insert, append as _append, watchEffect as _watchEffect, setText as _setText } from 'vue/vapor';
240+
"import { template as _template, children as _children, createTextNode as _createTextNode, prepend as _prepend, insert as _insert, append as _append, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
241241
242242
export function render(_ctx) {
243243
const t0 = _template("3<!>6<!>9")
@@ -255,28 +255,28 @@ export function render(_ctx) {
255255
_insert([n3, n4], n0, n9)
256256
_insert([n5, n6], n0, n10)
257257
_append(n0, n7, n8)
258-
_watchEffect(() => {
258+
_renderEffect(() => {
259259
_setText(n1, undefined, 1)
260260
})
261-
_watchEffect(() => {
261+
_renderEffect(() => {
262262
_setText(n2, undefined, 2)
263263
})
264-
_watchEffect(() => {
264+
_renderEffect(() => {
265265
_setText(n3, undefined, 4)
266266
})
267-
_watchEffect(() => {
267+
_renderEffect(() => {
268268
_setText(n4, undefined, 5)
269269
})
270-
_watchEffect(() => {
270+
_renderEffect(() => {
271271
_setText(n5, undefined, 7)
272272
})
273-
_watchEffect(() => {
273+
_renderEffect(() => {
274274
_setText(n6, undefined, 8)
275275
})
276-
_watchEffect(() => {
276+
_renderEffect(() => {
277277
_setText(n7, undefined, 'A')
278278
})
279-
_watchEffect(() => {
279+
_renderEffect(() => {
280280
_setText(n8, undefined, 'B')
281281
})
282282
return n0

packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`compiler v-bind > .camel modifier 1`] = `
4-
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
4+
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
55
66
export function render(_ctx) {
77
const t0 = _template("<div></div>")
88
const n0 = t0()
99
const { 0: [n1],} = _children(n0)
10-
_watchEffect(() => {
10+
_renderEffect(() => {
1111
_setAttr(n1, "fooBar", undefined, _ctx.id)
1212
})
1313
return n0
@@ -21,77 +21,77 @@ export function render(_ctx) {
2121
const t0 = _template("<div></div>")
2222
const n0 = t0()
2323
const { 0: [n1],} = _children(n0)
24-
_watchEffect(() => {
24+
_renderEffect(() => {
2525
_setAttr(n1, _camelize(_ctx.foo), undefined, _ctx.id)
2626
})
2727
return n0
2828
}"
2929
`;
3030

3131
exports[`compiler v-bind > .camel modifier w/ no expression 1`] = `
32-
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
32+
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
3333
3434
export function render(_ctx) {
3535
const t0 = _template("<div></div>")
3636
const n0 = t0()
3737
const { 0: [n1],} = _children(n0)
38-
_watchEffect(() => {
38+
_renderEffect(() => {
3939
_setAttr(n1, "fooBar", undefined, _ctx.fooBar)
4040
})
4141
return n0
4242
}"
4343
`;
4444

4545
exports[`compiler v-bind > basic 1`] = `
46-
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
46+
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
4747
4848
export function render(_ctx) {
4949
const t0 = _template("<div></div>")
5050
const n0 = t0()
5151
const { 0: [n1],} = _children(n0)
52-
_watchEffect(() => {
52+
_renderEffect(() => {
5353
_setAttr(n1, "id", undefined, _ctx.id)
5454
})
5555
return n0
5656
}"
5757
`;
5858

5959
exports[`compiler v-bind > dynamic arg 1`] = `
60-
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
60+
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
6161
6262
export function render(_ctx) {
6363
const t0 = _template("<div></div>")
6464
const n0 = t0()
6565
const { 0: [n1],} = _children(n0)
66-
_watchEffect(() => {
66+
_renderEffect(() => {
6767
_setAttr(n1, _ctx.id, undefined, _ctx.id)
6868
})
6969
return n0
7070
}"
7171
`;
7272

7373
exports[`compiler v-bind > no expression (shorthand) 1`] = `
74-
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
74+
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
7575
7676
export function render(_ctx) {
7777
const t0 = _template("<div></div>")
7878
const n0 = t0()
7979
const { 0: [n1],} = _children(n0)
80-
_watchEffect(() => {
80+
_renderEffect(() => {
8181
_setAttr(n1, "camel-case", undefined, _ctx.camelCase)
8282
})
8383
return n0
8484
}"
8585
`;
8686

8787
exports[`compiler v-bind > no expression 1`] = `
88-
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
88+
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
8989
9090
export function render(_ctx) {
9191
const t0 = _template("<div></div>")
9292
const n0 = t0()
9393
const { 0: [n1],} = _children(n0)
94-
_watchEffect(() => {
94+
_renderEffect(() => {
9595
_setAttr(n1, "id", undefined, _ctx.id)
9696
})
9797
return n0

packages/compiler-vapor/__tests__/transforms/__snapshots__/vHtml.spec.ts.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`v-html > should convert v-html to innerHTML 1`] = `
4-
"import { template as _template, children as _children, watchEffect as _watchEffect, setHtml as _setHtml } from 'vue/vapor';
4+
"import { template as _template, children as _children, renderEffect as _renderEffect, setHtml as _setHtml } from 'vue/vapor';
55
66
export function render(_ctx) {
77
const t0 = _template("<div></div>")
88
const n0 = t0()
99
const { 0: [n1],} = _children(n0)
10-
_watchEffect(() => {
10+
_renderEffect(() => {
1111
_setHtml(n1, undefined, _ctx.code)
1212
})
1313
return n0
1414
}"
1515
`;
1616

1717
exports[`v-html > should raise error and ignore children when v-html is present 1`] = `
18-
"import { template as _template, children as _children, watchEffect as _watchEffect, setHtml as _setHtml } from 'vue/vapor';
18+
"import { template as _template, children as _children, renderEffect as _renderEffect, setHtml as _setHtml } from 'vue/vapor';
1919
2020
export function render(_ctx) {
2121
const t0 = _template("<div></div>")
2222
const n0 = t0()
2323
const { 0: [n1],} = _children(n0)
24-
_watchEffect(() => {
24+
_renderEffect(() => {
2525
_setHtml(n1, undefined, _ctx.test)
2626
})
2727
return n0

packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap

+6-18
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export function render(_ctx) {
1313
`;
1414

1515
exports[`v-on > dynamic arg 1`] = `
16-
"import { template as _template, children as _children, watchEffect as _watchEffect, on as _on } from 'vue/vapor';
16+
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
1717
1818
export function render(_ctx) {
1919
const t0 = _template("<div></div>")
2020
const n0 = t0()
2121
const { 0: [n1],} = _children(n0)
22-
_watchEffect(() => {
22+
_renderEffect(() => {
2323
_on(n1, _ctx.event, (...args) => (_ctx.handler && _ctx.handler(...args)))
2424
})
2525
return n0
@@ -109,13 +109,13 @@ export function render(_ctx) {
109109
`;
110110

111111
exports[`v-on > should transform click.middle 2`] = `
112-
"import { template as _template, children as _children, watchEffect as _watchEffect, on as _on, withModifiers as _withModifiers } from 'vue/vapor';
112+
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on, withModifiers as _withModifiers } from 'vue/vapor';
113113
114114
export function render(_ctx) {
115115
const t0 = _template("<div></div>")
116116
const n0 = t0()
117117
const { 0: [n1],} = _children(n0)
118-
_watchEffect(() => {
118+
_renderEffect(() => {
119119
_on(n1, (_ctx.event) === "click" ? "mouseup" : (_ctx.event), _withModifiers((...args) => (_ctx.test && _ctx.test(...args)), ["middle"]))
120120
})
121121
return n0
@@ -135,31 +135,19 @@ export function render(_ctx) {
135135
`;
136136

137137
exports[`v-on > should transform click.right 2`] = `
138-
"import { template as _template, children as _children, watchEffect as _watchEffect, on as _on, withKeys as _withKeys, withModifiers as _withModifiers } from 'vue/vapor';
138+
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on, withKeys as _withKeys, withModifiers as _withModifiers } from 'vue/vapor';
139139
140140
export function render(_ctx) {
141141
const t0 = _template("<div></div>")
142142
const n0 = t0()
143143
const { 0: [n1],} = _children(n0)
144-
_watchEffect(() => {
144+
_renderEffect(() => {
145145
_on(n1, (_ctx.event) === "click" ? "contextmenu" : (_ctx.event), _withKeys(_withModifiers((...args) => (_ctx.test && _ctx.test(...args)), ["right"]), ["right"]))
146146
})
147147
return n0
148148
}"
149149
`;
150150

151-
exports[`v-on > should wrap as function if expression is inline statement 1`] = `
152-
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
153-
154-
export function render(_ctx) {
155-
const t0 = _template("<div></div>")
156-
const n0 = t0()
157-
const { 0: [n1],} = _children(n0)
158-
_on(n1, "click", (...args) => (_ctx.i++ && _ctx.i++(...args)))
159-
return n0
160-
}"
161-
`;
162-
163151
exports[`v-on > should wrap keys guard for keyboard events or dynamic events 1`] = `
164152
"import { template as _template, children as _children, on as _on, withKeys as _withKeys, withModifiers as _withModifiers } from 'vue/vapor';
165153

0 commit comments

Comments
 (0)