From 0193422a41bb10c5b33dd4a685183614580bdc63 Mon Sep 17 00:00:00 2001 From: trbrc Date: Mon, 6 Jan 2020 15:12:26 +0100 Subject: [PATCH] Add store signature Not sure exactly what the syntax of these signatures are, but they look like TypeScript, so that's what I went with for the object literal too. --- site/content/docs/01-component-format.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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.