diff --git a/site/content/tutorial/08-stores/06-store-bindings/app-a/App.svelte b/site/content/tutorial/08-stores/06-store-bindings/app-a/App.svelte new file mode 100644 index 0000000000..3839224826 --- /dev/null +++ b/site/content/tutorial/08-stores/06-store-bindings/app-a/App.svelte @@ -0,0 +1,6 @@ + + +

{$greeting}

+ \ No newline at end of file diff --git a/site/content/tutorial/08-stores/06-store-bindings/app-a/stores.js b/site/content/tutorial/08-stores/06-store-bindings/app-a/stores.js new file mode 100644 index 0000000000..298598a412 --- /dev/null +++ b/site/content/tutorial/08-stores/06-store-bindings/app-a/stores.js @@ -0,0 +1,8 @@ +import { writable, derived } from 'svelte/store'; + +export const name = writable('world'); + +export const greeting = derived( + name, + $name => `Hello ${$name}!` +); \ No newline at end of file diff --git a/site/content/tutorial/08-stores/06-store-bindings/app-b/App.svelte b/site/content/tutorial/08-stores/06-store-bindings/app-b/App.svelte new file mode 100644 index 0000000000..52f04be957 --- /dev/null +++ b/site/content/tutorial/08-stores/06-store-bindings/app-b/App.svelte @@ -0,0 +1,10 @@ + + +

{$greeting}

+ + + \ No newline at end of file diff --git a/site/content/tutorial/08-stores/06-store-bindings/app-b/stores.js b/site/content/tutorial/08-stores/06-store-bindings/app-b/stores.js new file mode 100644 index 0000000000..298598a412 --- /dev/null +++ b/site/content/tutorial/08-stores/06-store-bindings/app-b/stores.js @@ -0,0 +1,8 @@ +import { writable, derived } from 'svelte/store'; + +export const name = writable('world'); + +export const greeting = derived( + name, + $name => `Hello ${$name}!` +); \ No newline at end of file diff --git a/site/content/tutorial/08-stores/06-store-bindings/text.md b/site/content/tutorial/08-stores/06-store-bindings/text.md new file mode 100644 index 0000000000..7034703f33 --- /dev/null +++ b/site/content/tutorial/08-stores/06-store-bindings/text.md @@ -0,0 +1,23 @@ +--- +title: Store bindings +--- + +If a store is writable — i.e. it has a `set` method — you can bind to its value, just as you can bind to local component state. + +In this example we have a writable store `name` and a derived store `greeting`. Update the `` element: + +```html + +``` + +Changing the input value will now update `name` and all its dependents. + +We can also assign directly to store values inside a component. Add a ` +``` + +The `$name += '!'` assignment is equivalent to `name.set($name + '!')`. \ No newline at end of file