Skip to content

Commit c715203

Browse files
committed
perf(compiler-vaporl): finer update granularity
related #154
1 parent b2259a5 commit c715203

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const t0 = _template("foo")
66
77
export function render(_ctx) {
88
const _component_Comp = _resolveComponent("Comp")
9-
const n2 = _createComponent(_component_Comp, null, null, () => [{
9+
const n2 = _createComponent(_component_Comp, null, null, [() => ({
1010
name: _ctx.name,
1111
fn: () => {
1212
const n0 = t0()
1313
return n0
1414
}
15-
}], true)
15+
})], true)
1616
return n2
1717
}"
1818
`;
@@ -23,13 +23,13 @@ const t0 = _template("foo")
2323
2424
export function render(_ctx) {
2525
const _component_Comp = _resolveComponent("Comp")
26-
const n2 = _createComponent(_component_Comp, null, null, () => [_createForSlots(_ctx.list, (item) => ({
26+
const n2 = _createComponent(_component_Comp, null, null, [() => (_createForSlots(_ctx.list, (item) => ({
2727
name: item,
2828
fn: () => {
2929
const n0 = t0()
3030
return n0
3131
}
32-
}))], true)
32+
})))], true)
3333
return n2
3434
}"
3535
`;
@@ -40,13 +40,13 @@ const t0 = _template("foo")
4040
4141
export function render(_ctx) {
4242
const _component_Comp = _resolveComponent("Comp")
43-
const n2 = _createComponent(_component_Comp, null, null, () => [_createForSlots(_ctx.list, (_, __, index) => ({
43+
const n2 = _createComponent(_component_Comp, null, null, [() => (_createForSlots(_ctx.list, (_, __, index) => ({
4444
name: index,
4545
fn: () => {
4646
const n0 = t0()
4747
return n0
4848
}
49-
}))], true)
49+
})))], true)
5050
return n2
5151
}"
5252
`;
@@ -59,7 +59,7 @@ const t2 = _template("else condition")
5959
6060
export function render(_ctx) {
6161
const _component_Comp = _resolveComponent("Comp")
62-
const n6 = _createComponent(_component_Comp, null, null, () => [_ctx.condition
62+
const n6 = _createComponent(_component_Comp, null, null, [() => (_ctx.condition
6363
? {
6464
name: "condition",
6565
fn: () => {
@@ -84,7 +84,7 @@ export function render(_ctx) {
8484
return n4
8585
},
8686
key: "2"
87-
}], true)
87+
})], true)
8888
return n6
8989
}"
9090
`;

packages/compiler-vapor/src/generators/component.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,30 @@ function genDynamicSlots(
159159
dynamicSlots: ComponentDynamicSlot[],
160160
context: CodegenContext,
161161
) {
162-
const slotsExpr = genMulti(
162+
return genMulti(
163163
dynamicSlots.length > 1 ? DELIMITERS_ARRAY_NEWLINE : DELIMITERS_ARRAY,
164-
...dynamicSlots.map(slot => genDynamicSlot(slot, context)),
164+
...dynamicSlots.map(slot => genDynamicSlot(slot, context, true)),
165165
)
166-
return ['() => ', ...slotsExpr]
167166
}
168167

169168
function genDynamicSlot(
170169
slot: ComponentDynamicSlot,
171170
context: CodegenContext,
171+
top = false,
172172
): CodeFragment[] {
173173
switch (slot.slotType) {
174174
case DynamicSlotType.BASIC:
175-
return genBasicDynamicSlot(slot, context)
175+
return top
176+
? ['() => (', ...genBasicDynamicSlot(slot, context), ')']
177+
: genBasicDynamicSlot(slot, context)
176178
case DynamicSlotType.LOOP:
177-
return genLoopSlot(slot, context)
179+
return top
180+
? ['() => (', ...genLoopSlot(slot, context), ')']
181+
: genLoopSlot(slot, context)
178182
case DynamicSlotType.CONDITIONAL:
179-
return genConditionalSlot(slot, context)
183+
return top
184+
? ['() => (', ...genConditionalSlot(slot, context), ')']
185+
: genConditionalSlot(slot, context)
180186
}
181187
}
182188

packages/runtime-vapor/src/componentSlots.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export interface DynamicSlot {
3333
key?: string
3434
}
3535

36-
export type DynamicSlots = () => (DynamicSlot | DynamicSlot[])[]
36+
type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
37+
38+
export type DynamicSlots = DynamicSlotFn[]
3739

3840
export function initSlots(
3941
instance: ComponentInternalInstance,

0 commit comments

Comments
 (0)