Creating a debounced higher-order Svelte store
The two preceding sections that we’ve seen so far each created a new Svelte store. In this section, we are going to look at how we can create a higher-order store.
The concept of a higher-order store is inspired by a higher-order function, where functions are treated just like any other data. This means that you can pass functions as arguments to other functions or return them as values.
In a similar concept, we are going to create a function that treats stores just like any data, taking a Svelte store as an argument and then returning a Svelte store.
The idea of a higher-order Svelte store is to create a function that enhances an existing Svelte store. A higher-order Svelte store is a function that takes in a Svelte store and returns a new Svelte store, an enhanced version of the input Svelte store.
The example that we are going to use to illustrate this idea will create a debounce
higher-order Svelte store.
The...