Readable store that allows reading by subscription. Unlike writable stores, readable stores cannot be updated from the outside - their value can only be set by the start function.
Usage
Signature
Initial value of the store.
A function that is called when the first subscriber subscribes. It receives
set and update functions and optionally returns a cleanup function that is called when the last subscriber unsubscribes.A readable store object with the following method:
Subscribe to value changes. The
run callback is called immediately with the current value and then called again whenever the value changes.Returns an unsubscriber function.Store Contract
A readable store implements the following contract:subscribe
Subscribe to value changes:set or update methods accessible from the outside. The value can only be changed from within the start function.
Examples
Current time store
Mouse position store
Geolocation store
Auto-subscription with $
In Svelte components, you can use the$ prefix to automatically subscribe and unsubscribe: