diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index efc9937e5b..d9cab21950 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -174,7 +174,15 @@ Local variables (that do not represent store values) must *not* have a `$` prefi --- -You can create your own stores without relying on [`svelte/store`](docs#svelte_store), by implementing the **store contract**: +##### Store contract + +```js +store = { subscribe: (subscription: (value: any) => void) => () => void, set?: (value: any) => void } +``` + +--- + +You can create your own stores without relying on [`svelte/store`](docs#svelte_store), by implementing the *store contract*: 1. 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. 2. The `.subscribe` method must return an unsubscribe function. Calling an unsubscribe function must stop its subscription, and its corresponding subscription function must not be called again by the store.