perf(compiler-vapor): combine effect

This commit is contained in:
三咲智子 Kevin Deng 2023-12-07 01:09:03 +08:00
parent 082b6c40b5
commit 8786c076d9
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 22 additions and 11 deletions

View File

@ -328,14 +328,8 @@ export function render(_ctx) {
_on(n4, "click", (...args) => (_ctx.handleClick && _ctx.handleClick(...args)))
_effect(() => {
_setText(n1, undefined, _ctx.count)
})
_effect(() => {
_setText(n2, undefined, _ctx.count)
})
_effect(() => {
_setText(n3, undefined, _ctx.count)
})
_effect(() => {
_setAttr(n4, "id", undefined, _ctx.count)
})
return n0

View File

@ -113,11 +113,28 @@ function createRootContext(
) {
return this.registerOperation(...operations)
}
// TODO combine effects
effect.push({
expressions: expressions as IRExpression[],
operations,
})
const existing = effect.find((e) =>
isSameExpression(e.expressions, expressions as IRExpression[]),
)
if (existing) {
existing.operations.push(...operations)
} else {
effect.push({
expressions: expressions as IRExpression[],
operations,
})
}
function isSameExpression(a: IRExpression[], b: IRExpression[]) {
if (a.length !== b.length) return false
return a.every(
(exp, i) => identifyExpression(exp) === identifyExpression(b[i]),
)
}
function identifyExpression(exp: IRExpression) {
return typeof exp === 'string' ? exp : exp.content
}
},
template: '',