From 23fec168f550e7a79bbedfd5deaf35beabfd7e1d Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 18 Jul 2019 10:22:17 -0400 Subject: [PATCH] clarify that svelte/store follows the contract --- site/content/docs/01-component-format.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index f522260985..3d349af51d 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -149,6 +149,8 @@ If a statement consists entirely of an assignment to an undeclared variable, Sve A *store* is any object that allows reactive access to a value via a simple *store contract*. +The [`svelte/store` module](docs#svelte_store) contains minimal store implementations which fulfil this contract. You can use these as the basis for your own stores, or you can implement your stores from scratch. + A store must contain a `.subscribe` method, which must accept as its argument a subscription function. This subscription function must be immediately and synchronously called with the store's current value upon calling `.subscribe`. All of a store's active subscription functions must later be synchronously called whenever the store's value changes. The `.subscribe` method must also return an unsubscription function. Calling an unsubscription function must stop its subscription, and its corresponding subscription function must not be called again by the store. A store may optionally contain a `.set` method, which must accept as its argument a new value for the store, and which synchronously calls all of the store's active subscription functions. Such a store is called a *writable store*. @@ -162,8 +164,6 @@ const unsubscribe = store.subscribe(value => { unsubscribe(); ``` -The [`svelte/store` module](docs#svelte_store) contains a minimal store implementation. - --- Any time you have a reference to a store, you can access its value inside a component by prefixing it with the `$` character. This causes Svelte to declare the prefixed variable, and set up a store subscription that will be unsubscribed when appropriate.