Skip to content

Commit d9a6448

Browse files
committed
chore: remove selector api
1 parent 5a6afe5 commit d9a6448

File tree

7 files changed

+2
-188
lines changed

7 files changed

+2
-188
lines changed

packages/svelte/src/internal/client/runtime.js

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,105 +1243,6 @@ export function set_signal_status(signal, status) {
12431243
}
12441244
}
12451245

1246-
/** @template V */
1247-
class Selector {
1248-
/** @type {Map<V, Set<import('./types.js').Signal>>} */
1249-
#consumers_map = new Map();
1250-
1251-
/** @type {import('./types.js').Signal<V | null>} */
1252-
#active_key;
1253-
1254-
/** @param {V | null} [key] */
1255-
constructor(key) {
1256-
this.#active_key = source(key || null);
1257-
}
1258-
1259-
get current() {
1260-
return get(this.#active_key);
1261-
}
1262-
1263-
/**
1264-
* @param {V | null} key
1265-
* @returns {void}
1266-
*/
1267-
set(key) {
1268-
const active_key = this.#active_key;
1269-
const previous_key = active_key.value;
1270-
if (previous_key === key) {
1271-
return;
1272-
}
1273-
1274-
set_signal_value(active_key, key);
1275-
1276-
const consumers_map = this.#consumers_map;
1277-
let consumers = map_get(consumers_map, /** @type {V} */ (previous_key));
1278-
if (consumers !== undefined) {
1279-
this.#update_consumers(consumers);
1280-
}
1281-
1282-
consumers = map_get(consumers_map, /** @type {V} */ (key));
1283-
if (consumers !== undefined) {
1284-
this.#update_consumers(consumers);
1285-
}
1286-
}
1287-
1288-
/**
1289-
* @param {Set<import('./types.js').Signal>} consumers
1290-
* @returns {void}
1291-
*/
1292-
#update_consumers(consumers) {
1293-
let consumer;
1294-
for (consumer of consumers) {
1295-
set_signal_status(consumer, DIRTY);
1296-
if ((consumer.flags & IS_EFFECT) !== 0) {
1297-
schedule_effect(/** @type {import('./types.js').EffectSignal} */ (consumer), false);
1298-
} else {
1299-
mark_signal_consumers(consumer, DIRTY, true);
1300-
}
1301-
}
1302-
}
1303-
1304-
/**
1305-
* @param {V} key
1306-
* @returns {boolean}
1307-
*/
1308-
is(key) {
1309-
const consumers_map = this.#consumers_map;
1310-
let consumers = map_get(consumers_map, key);
1311-
if (consumers === undefined) {
1312-
consumers = new Set();
1313-
map_set(consumers_map, key, consumers);
1314-
}
1315-
1316-
const consumer = current_consumer;
1317-
const effect = current_effect;
1318-
if (effect !== null && consumer !== null && !consumers.has(consumer)) {
1319-
consumers.add(consumer);
1320-
push_destroy_fn(effect, () => {
1321-
const consumers_set = /** @type {Set<import('./types.js').Signal>} */ (consumers);
1322-
consumers_set.delete(effect);
1323-
if (consumers_set.size === 0) {
1324-
map_delete(consumers_map, key);
1325-
}
1326-
});
1327-
}
1328-
return this.#active_key.value === key;
1329-
}
1330-
}
1331-
1332-
/**
1333-
* `selector` allows you to track the currently selected item in a list in a performance optimized manner
1334-
* that runs in constant time (O(1)) - this is only noticable for very large lists.
1335-
*
1336-
* https://svelte-5-preview.vercel.app/docs/functions#selector
1337-
* @template Key
1338-
* @param {Key | null} [key]
1339-
* @returns {Selector<Key>}
1340-
*/
1341-
export function selector(key) {
1342-
return new Selector(key);
1343-
}
1344-
13451246
/**
13461247
* @template V
13471248
* @param {V | import('./types.js').Signal<V>} val

packages/svelte/src/internal/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export {
1313
user_effect,
1414
render_effect,
1515
pre_effect,
16-
selector,
1716
flushSync,
1817
bubble_event,
1918
safe_equal,

packages/svelte/src/main/main-client.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,4 @@ export function afterUpdate(fn) {
255255

256256
// TODO bring implementations in here
257257
// (except probably untrack — do we want to expose that, if there's also a rune?)
258-
export {
259-
flushSync,
260-
createRoot,
261-
mount,
262-
tick,
263-
untrack,
264-
onDestroy,
265-
selector
266-
} from '../internal/index.js';
258+
export { flushSync, createRoot, mount, tick, untrack, onDestroy } from '../internal/index.js';

packages/svelte/src/main/main-server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export {
77
hasContext,
88
mount,
99
onDestroy,
10-
selector,
1110
setContext,
1211
tick,
1312
untrack

packages/svelte/tests/runtime-runes/samples/selector/_config.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/svelte/tests/runtime-runes/samples/selector/main.svelte

Lines changed: 0 additions & 11 deletions
This file was deleted.

sites/svelte-5-preview/src/routes/docs/content/01-api/03-functions.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Functions
33
---
44

5-
As well as runes, Svelte 5 will introduce a couple of new functions, in addition to existing functions like `getContext`, `setContext` and `tick`. These are introduced as functions rather than runes because they are used directly and the compiler does not need to touch them to make them function as it does with runes. However, these functions may still use Svelte internals.
5+
As well as runes, Svelte 5 will introduces a some new functions, in addition to existing functions like `getContext`, `setContext` and `tick`. These are introduced as functions rather than runes because they are used directly and the compiler does not need to touch them to make them function as it does with runes. However, these functions may still use Svelte internals.
66

77
## `untrack`
88

@@ -22,22 +22,3 @@ To prevent something from being treated as an `$effect`/`$derived` dependency, u
2222
});
2323
</script>
2424
```
25-
26-
## `selector`
27-
28-
`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:
29-
30-
```svelte
31-
<script>
32-
import { selector } from 'svelte';
33-
34-
let array = $state([1, 2, 3]);
35-
let selected = selector();
36-
</script>
37-
38-
{#each array as item}
39-
<button on:click={() => selected.set(item)}>{selected.is(item)}</button>
40-
{/each}
41-
42-
<p>{selected.current}</p>
43-
```

0 commit comments

Comments
 (0)