From d56e0d50806a176fb17ee420622c9551694ffb90 Mon Sep 17 00:00:00 2001 From: Rohan Faiyaz Khan Date: Mon, 22 Jul 2019 01:01:44 +0600 Subject: [PATCH 1/3] Update 03-run-time.md Added descriptors for set and update methods of the return object of writable in svelte/store. --- site/content/docs/03-run-time.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 8d34c60f42..5d73bfdbcb 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -225,7 +225,13 @@ store = writable(value: any, (set: (value: any) => void) => () => void) --- -Creates a store with additional `set` and `update` methods. +Function that creates a store which has values that can be set from 'outside' components. It gets created as an object with additional `set` and `update` methods. + +`set` is a method that takes one argument which is the value to be set. The store value gets set to the value of the argument if the store value is not already equal to it. + +`update` is a method that takes one argument which is a callback. The callback takes the existing store value as its argument and returns the new value to be set to the store. + +If a function is passed as the second argument to the `writable` function, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero. ```js import { writable } from 'svelte/store'; @@ -243,7 +249,6 @@ count.update(n => n + 1); // logs '2' --- -If a function is passed as the second argument, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero. ```js import { writable } from 'svelte/store'; From 8851d79533cb68b4fd2c05f9d51140ec041b7f5e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Jul 2019 08:49:04 -0400 Subject: [PATCH 2/3] put second argument section back with its code sample --- site/content/docs/03-run-time.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 5d73bfdbcb..0c279874b9 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -231,8 +231,6 @@ Function that creates a store which has values that can be set from 'outside' co `update` is a method that takes one argument which is a callback. The callback takes the existing store value as its argument and returns the new value to be set to the store. -If a function is passed as the second argument to the `writable` function, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero. - ```js import { writable } from 'svelte/store'; @@ -249,6 +247,7 @@ count.update(n => n + 1); // logs '2' --- +If a function is passed as the second argument to the `writable` function, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero. ```js import { writable } from 'svelte/store'; From 695ace3665f1bc7655d40fe6cc02e56215b5a464 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Jul 2019 08:50:15 -0400 Subject: [PATCH 3/3] Update 03-run-time.md --- site/content/docs/03-run-time.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 0c279874b9..6d5777aacd 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -247,7 +247,7 @@ count.update(n => n + 1); // logs '2' --- -If a function is passed as the second argument to the `writable` function, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero. +If a function is passed as the second argument, it will be called when the number of subscribers goes from zero to one (but not from one to two, etc). That function will be passed a `set` function which changes the value of the store. It must return a `stop` function that is called when the subscriber count goes from one to zero. ```js import { writable } from 'svelte/store';