diff --git a/.changeset/chilly-dolphins-lick.md b/.changeset/chilly-dolphins-lick.md new file mode 100644 index 0000000000..1941f0a6a0 --- /dev/null +++ b/.changeset/chilly-dolphins-lick.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +chore: remove selector api diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 1a217c5626..a67f300b21 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -1254,105 +1254,6 @@ export function set_signal_status(signal, status) { } } -/** @template V */ -class Selector { - /** @type {Map>} */ - #consumers_map = new Map(); - - /** @type {import('./types.js').Signal} */ - #active_key; - - /** @param {V | null} [key] */ - constructor(key) { - this.#active_key = source(key || null); - } - - get current() { - return get(this.#active_key); - } - - /** - * @param {V | null} key - * @returns {void} - */ - set(key) { - const active_key = this.#active_key; - const previous_key = active_key.value; - if (previous_key === key) { - return; - } - - set_signal_value(active_key, key); - - const consumers_map = this.#consumers_map; - let consumers = map_get(consumers_map, /** @type {V} */ (previous_key)); - if (consumers !== undefined) { - this.#update_consumers(consumers); - } - - consumers = map_get(consumers_map, /** @type {V} */ (key)); - if (consumers !== undefined) { - this.#update_consumers(consumers); - } - } - - /** - * @param {Set} consumers - * @returns {void} - */ - #update_consumers(consumers) { - let consumer; - for (consumer of consumers) { - set_signal_status(consumer, DIRTY); - if ((consumer.flags & IS_EFFECT) !== 0) { - schedule_effect(/** @type {import('./types.js').EffectSignal} */ (consumer), false); - } else { - mark_signal_consumers(consumer, DIRTY, true); - } - } - } - - /** - * @param {V} key - * @returns {boolean} - */ - is(key) { - const consumers_map = this.#consumers_map; - let consumers = map_get(consumers_map, key); - if (consumers === undefined) { - consumers = new Set(); - map_set(consumers_map, key, consumers); - } - - const consumer = current_consumer; - const effect = current_effect; - if (effect !== null && consumer !== null && !consumers.has(consumer)) { - consumers.add(consumer); - push_destroy_fn(effect, () => { - const consumers_set = /** @type {Set} */ (consumers); - consumers_set.delete(effect); - if (consumers_set.size === 0) { - map_delete(consumers_map, key); - } - }); - } - return this.#active_key.value === key; - } -} - -/** - * `selector` allows you to track the currently selected item in a list in a performance optimized manner - * that runs in constant time (O(1)) - this is only noticable for very large lists. - * - * https://svelte-5-preview.vercel.app/docs/functions#selector - * @template Key - * @param {Key | null} [key] - * @returns {Selector} - */ -export function selector(key) { - return new Selector(key); -} - /** * @template V * @param {V | import('./types.js').Signal} val diff --git a/packages/svelte/src/internal/index.js b/packages/svelte/src/internal/index.js index ab24dad496..a0796cd37d 100644 --- a/packages/svelte/src/internal/index.js +++ b/packages/svelte/src/internal/index.js @@ -13,7 +13,6 @@ export { user_effect, render_effect, pre_effect, - selector, flushSync, bubble_event, safe_equal, diff --git a/packages/svelte/src/main/main-client.js b/packages/svelte/src/main/main-client.js index c6a14f3408..0971ebdc14 100644 --- a/packages/svelte/src/main/main-client.js +++ b/packages/svelte/src/main/main-client.js @@ -255,12 +255,4 @@ export function afterUpdate(fn) { // TODO bring implementations in here // (except probably untrack — do we want to expose that, if there's also a rune?) -export { - flushSync, - createRoot, - mount, - tick, - untrack, - onDestroy, - selector -} from '../internal/index.js'; +export { flushSync, createRoot, mount, tick, untrack, onDestroy } from '../internal/index.js'; diff --git a/packages/svelte/src/main/main-server.js b/packages/svelte/src/main/main-server.js index 3ff8962cf4..b9f81c5253 100644 --- a/packages/svelte/src/main/main-server.js +++ b/packages/svelte/src/main/main-server.js @@ -7,7 +7,6 @@ export { hasContext, mount, onDestroy, - selector, setContext, tick, untrack diff --git a/packages/svelte/tests/runtime-runes/samples/selector/_config.js b/packages/svelte/tests/runtime-runes/samples/selector/_config.js deleted file mode 100644 index f6c8c1620d..0000000000 --- a/packages/svelte/tests/runtime-runes/samples/selector/_config.js +++ /dev/null @@ -1,47 +0,0 @@ -import { test } from '../../test'; - -export default test({ - html: ` - - - -

- `, - - async test({ assert, target }) { - const [b1, b2, b3] = target.querySelectorAll('button'); - - await b1.click(); - assert.htmlEqual( - target.innerHTML, - ` - - - -

1

- ` - ); - - await b3.click(); - assert.htmlEqual( - target.innerHTML, - ` - - - -

3

- ` - ); - - await b2.click(); - assert.htmlEqual( - target.innerHTML, - ` - - - -

2

- ` - ); - } -}); diff --git a/packages/svelte/tests/runtime-runes/samples/selector/main.svelte b/packages/svelte/tests/runtime-runes/samples/selector/main.svelte deleted file mode 100644 index b48c63ff0f..0000000000 --- a/packages/svelte/tests/runtime-runes/samples/selector/main.svelte +++ /dev/null @@ -1,11 +0,0 @@ - - -{#each array as item} - -{/each} - -

{selected.current}

diff --git a/sites/svelte-5-preview/src/routes/docs/content/01-api/03-functions.md b/sites/svelte-5-preview/src/routes/docs/content/01-api/03-functions.md index 6385c53a14..bb3bc3fe7e 100644 --- a/sites/svelte-5-preview/src/routes/docs/content/01-api/03-functions.md +++ b/sites/svelte-5-preview/src/routes/docs/content/01-api/03-functions.md @@ -23,21 +23,3 @@ To prevent something from being treated as an `$effect`/`$derived` dependency, u ``` -## `selector` - -`selector` allows you to track the currently selected item in a list in a performance optimized manner that runs in constant time (`O(1)`). With `selector`, you can immediately determine if an item is selected: - -```svelte - - -{#each array as item} - -{/each} - -

{selected.current}

-```