From 826090ecfb79ad5b6a248020473fadfceb04c7a4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 1 Dec 2023 00:53:01 -0500 Subject: [PATCH] don't think we need this any more --- packages/svelte/src/internal/client/each.js | 31 +++++--------------- packages/svelte/src/internal/client/proxy.js | 23 ++++----------- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/packages/svelte/src/internal/client/each.js b/packages/svelte/src/internal/client/each.js index 46b76011a6..e91b7ac2e3 100644 --- a/packages/svelte/src/internal/client/each.js +++ b/packages/svelte/src/internal/client/each.js @@ -15,7 +15,6 @@ import { set_current_hydration_fragment } from './hydration.js'; import { clear_text_content, map_get, map_set } from './operations.js'; -import { STATE_SYMBOL } from './proxy.js'; import { insert, remove } from './reconciler.js'; import { empty } from './render.js'; import { @@ -274,15 +273,9 @@ function reconcile_indexed_array( flags, apply_transitions ) { - var is_proxied_array = STATE_SYMBOL in array; var a_blocks = each_block.v; var active_transitions = each_block.s; - if (is_proxied_array) { - flags &= ~EACH_ITEM_REACTIVE; - flags |= EACH_IS_PROXIED; - } - /** @type {number | void} */ var a = a_blocks.length; @@ -345,7 +338,7 @@ function reconcile_indexed_array( item = array[index]; block = a_blocks[index]; b_blocks[index] = block; - update_each_item_block(block, item, index, flags); + update_each_item_block(block, index, flags); } } } @@ -385,14 +378,8 @@ function reconcile_tracked_array( ) { var a_blocks = each_block.v; const is_computed_key = keys !== null; - var is_proxied_array = STATE_SYMBOL in array; var active_transitions = each_block.s; - if (is_proxied_array) { - flags &= ~EACH_ITEM_REACTIVE; - flags |= EACH_IS_PROXIED; - } - /** @type {number | void} */ var a = a_blocks.length; @@ -469,7 +456,7 @@ function reconcile_tracked_array( while (a_blocks[a_end].k === key) { block = a_blocks[a_end--]; item = array[b_end]; - update_each_item_block(block, item, b_end, flags); + update_each_item_block(block, b_end, flags); sibling = get_first_child(block); b_blocks[b_end] = block; if (start > --b_end || start > a_end) { @@ -483,7 +470,7 @@ function reconcile_tracked_array( while (start <= a_end && start <= b_end && a_blocks[start].k === key) { item = array[start]; block = a_blocks[start]; - update_each_item_block(block, item, start, flags); + update_each_item_block(block, start, flags); b_blocks[start] = block; ++start; key = is_computed_key ? keys[start] : array[start]; @@ -544,7 +531,7 @@ function reconcile_tracked_array( a = sources[i]; if (pos === MOVED_BLOCK && a !== LIS_BLOCK) { block = b_blocks[b_end]; - update_each_item_block(block, item, b_end, flags); + update_each_item_block(block, b_end, flags); } } } @@ -561,7 +548,7 @@ function reconcile_tracked_array( } else { block = b_blocks[b_end]; if (!is_animated) { - update_each_item_block(block, item, b_end, flags); + update_each_item_block(block, b_end, flags); } } if (should_create || (pos === MOVED_BLOCK && a !== LIS_BLOCK)) { @@ -732,23 +719,21 @@ function get_first_element(block) { /** * @param {import('./types.js').EachItemBlock} block - * @param {any} item * @param {number} index * @param {number} type * @returns {void} */ -function update_each_item_block(block, item, index, type) { - if ((type & EACH_ITEM_REACTIVE) !== 0) { - set_signal_value(block.v, item); - } +function update_each_item_block(block, index, type) { const transitions = block.s; const index_is_reactive = (type & EACH_INDEX_REACTIVE) !== 0; + // Handle each item animations if (transitions !== null && (type & EACH_KEYED) !== 0) { let prev_index = block.i; if (index_is_reactive) { prev_index = /** @type {import('./types.js').Signal} */ (prev_index).v; } + const items = block.p.v; if (prev_index !== index && /** @type {number} */ (index) < items.length) { const from_dom = /** @type {Element} */ (get_first_element(block)); diff --git a/packages/svelte/src/internal/client/proxy.js b/packages/svelte/src/internal/client/proxy.js index 15ff427e53..2adb26e58c 100644 --- a/packages/svelte/src/internal/client/proxy.js +++ b/packages/svelte/src/internal/client/proxy.js @@ -1,7 +1,7 @@ import { effect_active, get, set, increment, source, updating_derived } from './runtime.js'; import { get_descriptor, is_array } from './utils.js'; -/** @typedef {{ p: StateObject | null; s: Map>; v: import('./types.js').SourceSignal; a: boolean }} Metadata */ +/** @typedef {{ s: Map>; v: import('./types.js').SourceSignal; a: boolean }} Metadata */ /** @typedef {Record & { [STATE_SYMBOL]: Metadata }} StateObject */ export const STATE_SYMBOL = Symbol(); @@ -18,24 +18,13 @@ const is_frozen = Object.isFrozen; * @returns {T} */ export function proxy(value) { - return wrap(value, null); -} - -/** - * @template {StateObject} T - * @template {StateObject} P - * @param {T} value - * @param {P | null} parent - * @returns {T} - */ -function wrap(value, parent) { if (typeof value === 'object' && value != null && !is_frozen(value) && !(STATE_SYMBOL in value)) { const prototype = get_prototype_of(value); // TODO handle Map and Set as well if (prototype === object_prototype || prototype === array_prototype) { // @ts-expect-error - value[STATE_SYMBOL] = init(value, parent); + value[STATE_SYMBOL] = init(value); // @ts-expect-error not sure how to fix this return new Proxy(value, handler); @@ -47,12 +36,10 @@ function wrap(value, parent) { /** * @param {StateObject} value - * @param {StateObject | null} parent * @returns {Metadata} */ -function init(value, parent) { +function init(value) { return { - p: parent, s: new Map(), v: source(0), a: is_array(value) @@ -76,7 +63,7 @@ const handler = { (effect_active() || updating_derived) && (!(prop in target) || get_descriptor(target, prop)?.writable) ) { - s = source(wrap(target[prop], receiver)); + s = source(proxy(target[prop])); metadata.s.set(prop, s); } @@ -86,7 +73,7 @@ const handler = { const metadata = target[STATE_SYMBOL]; const s = metadata.s.get(prop); - if (s !== undefined) set(s, wrap(value, target)); + if (s !== undefined) set(s, proxy(value)); if (metadata.a && prop === 'length') { for (let i = value; i < target.length; i += 1) {