From e46cb7a905408157fde949536e3c240e7b671d1a Mon Sep 17 00:00:00 2001 From: tanhauhau Date: Wed, 23 Jun 2021 15:01:44 +0800 Subject: [PATCH] cleaning up --- .../compile/render_dom/wrappers/Slot.ts | 39 ++++++++++++------- src/runtime/internal/utils.ts | 14 +++---- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Slot.ts b/src/compiler/compile/render_dom/wrappers/Slot.ts index 0d33c2d4db..09366dcaaf 100644 --- a/src/compiler/compile/render_dom/wrappers/Slot.ts +++ b/src/compiler/compile/render_dom/wrappers/Slot.ts @@ -165,26 +165,39 @@ export default class SlotWrapper extends Wrapper { : []; let condition = renderer.dirty(dynamic_dependencies); - let dirty = x`#dirty`; - let fallback_dirty = x`#dirty`; if (block.has_outros) { condition = x`!#current || ${condition}`; - dirty = x`!#current || ${dirty}`; - fallback_dirty = x`!#current ? ${renderer.get_initial_dirty()} : ${fallback_dirty}`; } - const slot_update = get_slot_spread_changes_fn ? b` - if (${slot}.p && ${condition}) { - @update_slot_spread(${slot}, ${slot_definition}, #ctx, ${renderer.reference('$$scope')}, ${dirty}, ${get_slot_changes_fn}, ${get_slot_spread_changes_fn}, ${get_slot_context_fn}); - } - ` : b` - if (${slot}.p && ${condition}) { - @update_slot(${slot}, ${slot_definition}, #ctx, ${renderer.reference('$$scope')}, ${dirty}, ${get_slot_changes_fn}, ${get_slot_context_fn}); - } - `; + // conditions to treat everything as dirty + const all_dirty_conditions = [ + get_slot_spread_changes_fn ? x`${get_slot_spread_changes_fn}(#dirty)` : null, + block.has_outros ? x`!#current` : null + ].filter(Boolean); + const all_dirty_condition = all_dirty_conditions.length ? all_dirty_conditions.reduce((condition1, condition2) => x`${condition1} || ${condition2}`): null; + + let slot_update; + if (all_dirty_condition) { + const dirty = x`${all_dirty_condition} ? @get_all_dirty_from_scope(${renderer.reference('$$scope')}) : @get_slot_changes(${slot_definition}, ${renderer.reference('$$scope')}, #dirty, ${get_slot_changes_fn})`; + + slot_update = b` + if (${slot}.p && ${condition}) { + @update_slot_base(${slot}, ${slot_definition}, #ctx, ${renderer.reference('$$scope')}, ${dirty}, ${get_slot_context_fn}); + } + `; + } else { + slot_update = b` + if (${slot}.p && ${condition}) { + @update_slot(${slot}, ${slot_definition}, #ctx, ${renderer.reference('$$scope')}, #dirty, ${get_slot_changes_fn}, ${get_slot_context_fn}); + } + `; + } + let fallback_condition = renderer.dirty(fallback_dynamic_dependencies); + let fallback_dirty = x`#dirty`; if (block.has_outros) { fallback_condition = x`!#current || ${fallback_condition}`; + fallback_dirty = x`!#current ? ${renderer.get_initial_dirty()} : ${fallback_dirty}`; } const fallback_update = has_fallback && fallback_dynamic_dependencies.length > 0 && b` diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index b46b4a4ef4..76870eba8c 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -109,23 +109,19 @@ export function get_slot_changes(definition, $$scope, dirty, fn) { return $$scope.dirty; } -export function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) { - const slot_changes = dirty === true ? get_all_dirty($$scope) : get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn); +export function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) { if (slot_changes) { const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn); slot.p(slot_context, slot_changes); } } -export function update_slot_spread(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_spread_changes_fn, get_slot_context_fn) { - const slot_changes = dirty === true || get_slot_spread_changes_fn(dirty) ? get_all_dirty($$scope) : get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn); - if (slot_changes) { - const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn); - slot.p(slot_context, slot_changes); - } +export function update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) { + const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn); + update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn); } -function get_all_dirty($$scope) { +export function get_all_dirty_from_scope($$scope) { if ($$scope.ctx.length > 32) { const dirty = []; const length = $$scope.ctx.length / 32;