-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Description
Describe the problem
In Svelte 4 Higher Order stores are supported. This is a great feature that allows to separation of concerns for stores.
But in svelte 5 I see now way to accomplish this feature:
The following modification of the svelte 5 tutorial shows the problem.
<script>
let count = $state(0);
function increment() {
count += 1;
}
// this would be a very generic function which could be reused with any store (if higher order stores would word):
function delayed(baseStore, delayLen) {
let resultStore = $state(baseStore);
const buffer = []
$effect(() => {
buffer.push(count);
if (buffer.length > delayLen) resultStore = buffer.shift()
})
return {
get val() { return resultStore; }
}
}
let delayedCount = delayed(count, 5);
</script>
<button on:click={increment}>
clicks: {delayedCount.val}
</button>
Describe the proposed solution
When passing a rune/signal as parameter I would intuitively expect, that it is handled as if the parameter is also a rune/signal WITHIN the function.
The example given above would then work out of the box.
Alternatives considered
If automatic detection of runes and passing them into function is hard, this could be done with an explicit wrapper like:
let delayedCount = delayed($use(count), 5)
But this is much more unintuitive and probably error prone, as devs will forget to add the $use
Importance
i cannot use svelte without it
Metadata
Metadata
Assignees
Labels
No labels