Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Real-World Svelte

You're reading from  Real-World Svelte

Product type Book
Published in Dec 2023
Publisher Packt
ISBN-13 9781804616031
Pages 282 pages
Edition 1st Edition
Languages
Author (1):
Tan Li Hau Tan Li Hau
Profile icon Tan Li Hau
Toc

Table of Contents (22) Chapters close

Preface 1. Part 1: Writing Svelte Components
2. Chapter 1: Lifecycles in Svelte 3. Chapter 2: Implementing Styling and Theming 4. Chapter 3: Managing Props and State 5. Chapter 4: Composing Components 6. Part 2: Actions
7. Chapter 5: Custom Events with Actions 8. Chapter 6: Integrating Libraries with Actions 9. Chapter 7: Progressive Enhancement with Actions 10. Part 3: Context and Stores
11. Chapter 8: Context versus Stores 12. Chapter 9: Implementing Custom Stores 13. Chapter 10: State Management with Svelte Stores 14. Chapter 11: Renderless Components 15. Chapter 12: Stores and Animations 16. Part 4: Transitions
17. Chapter 13: Using Transitions 18. Chapter 14: Exploring Custom Transitions 19. Chapter 15: Accessibility with Transitions 20. Index 21. Other Books You May Enjoy

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime