Skip to content

Commit cc511e6

Browse files
Doctor-wusxzz
authored andcommitted
perf(compiler-vaporl): finer update granularity
related #154
1 parent 208dbc6 commit cc511e6

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

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

+10-10
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: _withDestructure(({ bar }) => [bar], (_ctx0) => {
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
`;
@@ -151,13 +151,13 @@ exports[`compiler: transform slot > on component dynamically named slot 1`] = `
151151
152152
export function render(_ctx) {
153153
const _component_Comp = _resolveComponent("Comp")
154-
const n1 = _createComponent(_component_Comp, null, { }, () => [{
154+
const n1 = _createComponent(_component_Comp, null, { }, [() => ({
155155
name: _ctx.named,
156156
fn: _withDestructure(({ foo }) => [foo], (_ctx0) => {
157157
const n0 = _createTextNode(() => [_ctx0[0] + _ctx.bar])
158158
return n0
159159
})
160-
}], true)
160+
})], true)
161161
return n1
162162
}"
163163
`;

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,30 @@ function genDynamicSlots(
168168
dynamicSlots: ComponentDynamicSlot[],
169169
context: CodegenContext,
170170
) {
171-
const slotsExpr = genMulti(
171+
return genMulti(
172172
dynamicSlots.length > 1 ? DELIMITERS_ARRAY_NEWLINE : DELIMITERS_ARRAY,
173-
...dynamicSlots.map(slot => genDynamicSlot(slot, context)),
173+
...dynamicSlots.map(slot => genDynamicSlot(slot, context, true)),
174174
)
175-
return ['() => ', ...slotsExpr]
176175
}
177176

178177
function genDynamicSlot(
179178
slot: ComponentDynamicSlot,
180179
context: CodegenContext,
180+
top = false,
181181
): CodeFragment[] {
182182
switch (slot.slotType) {
183183
case DynamicSlotType.BASIC:
184-
return genBasicDynamicSlot(slot, context)
184+
return top
185+
? ['() => (', ...genBasicDynamicSlot(slot, context), ')']
186+
: genBasicDynamicSlot(slot, context)
185187
case DynamicSlotType.LOOP:
186-
return genLoopSlot(slot, context)
188+
return top
189+
? ['() => (', ...genLoopSlot(slot, context), ')']
190+
: genLoopSlot(slot, context)
187191
case DynamicSlotType.CONDITIONAL:
188-
return genConditionalSlot(slot, context)
192+
return top
193+
? ['() => (', ...genConditionalSlot(slot, context), ')']
194+
: genConditionalSlot(slot, context)
189195
}
190196
}
191197

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)