Skip to content

Commit

Permalink
feat: renderWatch / renderEffect (#86)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
LittleSound and sxzz authored Jan 6, 2024
1 parent bdf28de commit fb4d9a1
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 505 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`compile > bindings 1`] = `
"import { template as _template, children as _children, createTextNode as _createTextNode, insert as _insert, watchEffect as _watchEffect, setText as _setText } from 'vue/vapor';
"import { template as _template, children as _children, createTextNode as _createTextNode, insert as _insert, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div>count is <!>.</div>")
const n0 = t0()
const { 0: [n3, { 1: [n2],}],} = _children(n0)
const n1 = _createTextNode(_ctx.count)
_insert(n1, n3, n2)
_watchEffect(() => {
_renderEffect(() => {
_setText(n1, undefined, _ctx.count)
})
return n0
Expand Down Expand Up @@ -121,45 +121,45 @@ export function render(_ctx) {
`;

exports[`compile > directives > v-pre > self-closing v-pre 1`] = `
"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';
"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';
export function render(_ctx) {
const t0 = _template("<div></div><div><Comp></Comp></div>")
const n0 = t0()
const { 1: [n2],} = _children(n0)
const n1 = _createTextNode(_ctx.bar)
_append(n2, n1)
_watchEffect(() => {
_renderEffect(() => {
_setText(n1, undefined, _ctx.bar)
})
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n2, "id", undefined, _ctx.foo)
})
return n0
}"
`;

exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
"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';
"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';
export function render(_ctx) {
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>")
const n0 = t0()
const { 1: [n2],} = _children(n0)
const n1 = _createTextNode(_ctx.bar)
_append(n2, n1)
_watchEffect(() => {
_renderEffect(() => {
_setText(n1, undefined, _ctx.bar)
})
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n2, "id", undefined, _ctx.foo)
})
return n0
}"
`;

exports[`compile > dynamic root 1`] = `
"import { fragment as _fragment, createTextNode as _createTextNode, append as _append, watchEffect as _watchEffect, setText as _setText } from 'vue/vapor';
"import { fragment as _fragment, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
export function render(_ctx) {
const t0 = _fragment()
Expand All @@ -168,18 +168,18 @@ export function render(_ctx) {
const n1 = _createTextNode(1)
const n2 = _createTextNode(2)
_append(n0, n1, n2)
_watchEffect(() => {
_renderEffect(() => {
_setText(n1, undefined, 1)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n2, undefined, 2)
})
return n0
}"
`;

exports[`compile > dynamic root nodes and interpolation 1`] = `
"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';
"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';
export function render(_ctx) {
const t0 = _template("<button>foo<!>foo</button>")
Expand All @@ -192,7 +192,7 @@ export function render(_ctx) {
_insert(n2, n4, n5)
_append(n4, n3)
_on(n4, "click", (...args) => (_ctx.handleClick && _ctx.handleClick(...args)))
_watchEffect(() => {
_renderEffect(() => {
_setText(n1, undefined, _ctx.count)
_setText(n2, undefined, _ctx.count)
_setText(n3, undefined, _ctx.count)
Expand All @@ -207,7 +207,7 @@ exports[`compile > expression parsing > interpolation 1`] = `
const t0 = _fragment()
const n0 = t0()
_watchEffect(() => {
_renderEffect(() => {
_setText(n0, undefined, a + b.value)
})
return n0
Expand All @@ -219,7 +219,7 @@ exports[`compile > expression parsing > v-bind 1`] = `
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, key.value+1, undefined, _unref(foo)[key.value+1]())
})
return n0
Expand All @@ -237,7 +237,7 @@ export function render(_ctx) {
`;

exports[`compile > static + dynamic root 1`] = `
"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';
"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';
export function render(_ctx) {
const t0 = _template("3<!>6<!>9")
Expand All @@ -255,28 +255,28 @@ export function render(_ctx) {
_insert([n3, n4], n0, n9)
_insert([n5, n6], n0, n10)
_append(n0, n7, n8)
_watchEffect(() => {
_renderEffect(() => {
_setText(n1, undefined, 1)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n2, undefined, 2)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n3, undefined, 4)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n4, undefined, 5)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n5, undefined, 7)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n6, undefined, 8)
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n7, undefined, 'A')
})
_watchEffect(() => {
_renderEffect(() => {
_setText(n8, undefined, 'B')
})
return n0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`compiler v-bind > .camel modifier 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, "fooBar", undefined, _ctx.id)
})
return n0
Expand All @@ -21,77 +21,77 @@ export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, _camelize(_ctx.foo), undefined, _ctx.id)
})
return n0
}"
`;

exports[`compiler v-bind > .camel modifier w/ no expression 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, "fooBar", undefined, _ctx.fooBar)
})
return n0
}"
`;

exports[`compiler v-bind > basic 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, "id", undefined, _ctx.id)
})
return n0
}"
`;

exports[`compiler v-bind > dynamic arg 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, _ctx.id, undefined, _ctx.id)
})
return n0
}"
`;

exports[`compiler v-bind > no expression (shorthand) 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, "camel-case", undefined, _ctx.camelCase)
})
return n0
}"
`;

exports[`compiler v-bind > no expression 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setAttr as _setAttr } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setAttr(n1, "id", undefined, _ctx.id)
})
return n0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`v-html > should convert v-html to innerHTML 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setHtml as _setHtml } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setHtml as _setHtml } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setHtml(n1, undefined, _ctx.code)
})
return n0
}"
`;

exports[`v-html > should raise error and ignore children when v-html is present 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, setHtml as _setHtml } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, setHtml as _setHtml } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_setHtml(n1, undefined, _ctx.test)
})
return n0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function render(_ctx) {
`;

exports[`v-on > dynamic arg 1`] = `
"import { template as _template, children as _children, watchEffect as _watchEffect, on as _on } from 'vue/vapor';
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_watchEffect(() => {
_renderEffect(() => {
_on(n1, _ctx.event, (...args) => (_ctx.handler && _ctx.handler(...args)))
})
return n0
Expand Down Expand Up @@ -109,13 +109,13 @@ export function render(_ctx) {
`;

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

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

exports[`v-on > should wrap as function if expression is inline statement 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
export function render(_ctx) {
const t0 = _template("<div></div>")
const n0 = t0()
const { 0: [n1],} = _children(n0)
_on(n1, "click", (...args) => (_ctx.i++ && _ctx.i++(...args)))
return n0
}"
`;

exports[`v-on > should wrap keys guard for keyboard events or dynamic events 1`] = `
"import { template as _template, children as _children, on as _on, withKeys as _withKeys, withModifiers as _withModifiers } from 'vue/vapor';
Expand Down
Loading

0 comments on commit fb4d9a1

Please sign in to comment.