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 diff --git a/site/content/tutorial/10-transitions/07-deferred-transitions/app-a/App.svelte b/site/content/tutorial/10-transitions/07-deferred-transitions/app-a/App.svelte deleted file mode 100644 index c46096c204..0000000000 --- a/site/content/tutorial/10-transitions/07-deferred-transitions/app-a/App.svelte +++ /dev/null @@ -1,146 +0,0 @@ - - - - -
- - -
-

todo

- {#each todos.filter(t => !t.done) as todo (todo.id)} - - {/each} -
- -
-

done

- {#each todos.filter(t => t.done) as todo (todo.id)} - - {/each} -
-
\ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-deferred-transitions/app-a/crossfade.js b/site/content/tutorial/10-transitions/07-deferred-transitions/app-a/crossfade.js deleted file mode 100644 index e11e18b60e..0000000000 --- a/site/content/tutorial/10-transitions/07-deferred-transitions/app-a/crossfade.js +++ /dev/null @@ -1,65 +0,0 @@ -import { quintOut } from 'svelte/easing'; - -export default function crossfade({ send, receive, fallback }) { - let requested = new Map(); - let provided = new Map(); - - function crossfade(from, node) { - const to = node.getBoundingClientRect(); - const dx = from.left - to.left; - const dy = from.top - to.top; - - const style = getComputedStyle(node); - const transform = style.transform === 'none' ? '' : style.transform; - - return { - duration: 400, - easing: quintOut, - css: (t, u) => ` - opacity: ${t}; - transform: ${transform} translate(${u * dx}px,${u * dy}px); - ` - }; - } - - return { - send(node, params) { - provided.set(params.key, { - rect: node.getBoundingClientRect() - }); - - return () => { - if (requested.has(params.key)) { - const { rect } = requested.get(params.key); - requested.delete(params.key); - - return crossfade(rect, node); - } - - // if the node is disappearing altogether - // (i.e. wasn't claimed by the other list) - // then we need to supply an outro - provided.delete(params.key); - return fallback(node, params); - }; - }, - - receive(node, params) { - requested.set(params.key, { - rect: node.getBoundingClientRect() - }); - - return () => { - if (provided.has(params.key)) { - const { rect } = provided.get(params.key); - provided.delete(params.key); - - return crossfade(rect, node); - } - - requested.delete(params.key); - return fallback(node, params); - }; - } - }; -} \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-deferred-transitions/app-b/App.svelte b/site/content/tutorial/10-transitions/07-deferred-transitions/app-b/App.svelte deleted file mode 100644 index c46096c204..0000000000 --- a/site/content/tutorial/10-transitions/07-deferred-transitions/app-b/App.svelte +++ /dev/null @@ -1,146 +0,0 @@ - - - - -
- - -
-

todo

- {#each todos.filter(t => !t.done) as todo (todo.id)} - - {/each} -
- -
-

done

- {#each todos.filter(t => t.done) as todo (todo.id)} - - {/each} -
-
\ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-deferred-transitions/app-b/crossfade.js b/site/content/tutorial/10-transitions/07-deferred-transitions/app-b/crossfade.js deleted file mode 100644 index e11e18b60e..0000000000 --- a/site/content/tutorial/10-transitions/07-deferred-transitions/app-b/crossfade.js +++ /dev/null @@ -1,65 +0,0 @@ -import { quintOut } from 'svelte/easing'; - -export default function crossfade({ send, receive, fallback }) { - let requested = new Map(); - let provided = new Map(); - - function crossfade(from, node) { - const to = node.getBoundingClientRect(); - const dx = from.left - to.left; - const dy = from.top - to.top; - - const style = getComputedStyle(node); - const transform = style.transform === 'none' ? '' : style.transform; - - return { - duration: 400, - easing: quintOut, - css: (t, u) => ` - opacity: ${t}; - transform: ${transform} translate(${u * dx}px,${u * dy}px); - ` - }; - } - - return { - send(node, params) { - provided.set(params.key, { - rect: node.getBoundingClientRect() - }); - - return () => { - if (requested.has(params.key)) { - const { rect } = requested.get(params.key); - requested.delete(params.key); - - return crossfade(rect, node); - } - - // if the node is disappearing altogether - // (i.e. wasn't claimed by the other list) - // then we need to supply an outro - provided.delete(params.key); - return fallback(node, params); - }; - }, - - receive(node, params) { - requested.set(params.key, { - rect: node.getBoundingClientRect() - }); - - return () => { - if (provided.has(params.key)) { - const { rect } = provided.get(params.key); - provided.delete(params.key); - - return crossfade(rect, node); - } - - requested.delete(params.key); - return fallback(node, params); - }; - } - }; -} \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-deferred-transitions/text.md b/site/content/tutorial/10-transitions/07-deferred-transitions/text.md deleted file mode 100644 index e649762f57..0000000000 --- a/site/content/tutorial/10-transitions/07-deferred-transitions/text.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Deferred transitions ---- - -A particularly powerful feature of Svelte's transition engine is the ability to *defer* transitions, so that they can be coordinated between multiple elements. - -TODO https://github.com/sveltejs/svelte/issues/2159 \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-local-transitions/app-a/App.svelte b/site/content/tutorial/10-transitions/07-local-transitions/app-a/App.svelte new file mode 100644 index 0000000000..ed93815c0d --- /dev/null +++ b/site/content/tutorial/10-transitions/07-local-transitions/app-a/App.svelte @@ -0,0 +1,32 @@ + + + + + + + + +{#if showItems} + {#each items.slice(0, i) as item} +
+ {item} +
+ {/each} +{/if} \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-local-transitions/app-b/App.svelte b/site/content/tutorial/10-transitions/07-local-transitions/app-b/App.svelte new file mode 100644 index 0000000000..3d569cfcbb --- /dev/null +++ b/site/content/tutorial/10-transitions/07-local-transitions/app-b/App.svelte @@ -0,0 +1,32 @@ + + + + + + + + +{#if showItems} + {#each items.slice(0, i) as item} +
+ {item} +
+ {/each} +{/if} \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/07-local-transitions/text.md b/site/content/tutorial/10-transitions/07-local-transitions/text.md new file mode 100644 index 0000000000..7a22967ab0 --- /dev/null +++ b/site/content/tutorial/10-transitions/07-local-transitions/text.md @@ -0,0 +1,15 @@ +--- +title: Local transitions +--- + +Ordinarily, transitions will play on elements when any container block is added or destroyed. In the example here, toggling the visibility of the entire list also applies transitions to individual list elements. + +Instead, we'd like transitions to play only when individual items are added and removed — on other words, when the user drags the slider. + +We can achieve this with a *local* transition, which only plays when the immediate parent block is added or removed: + +```html +
+ {item} +
+``` \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/08-deferred-transitions/app-a/App.svelte b/site/content/tutorial/10-transitions/08-deferred-transitions/app-a/App.svelte new file mode 100644 index 0000000000..e869816730 --- /dev/null +++ b/site/content/tutorial/10-transitions/08-deferred-transitions/app-a/App.svelte @@ -0,0 +1,148 @@ + + +
+ e.which === 13 && add(e.target)} + > + +
+

todo

+ {#each todos.filter(t => !t.done) as todo (todo.id)} + + {/each} +
+ +
+

done

+ {#each todos.filter(t => t.done) as todo (todo.id)} + + {/each} +
+
+ + \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/08-deferred-transitions/app-b/App.svelte b/site/content/tutorial/10-transitions/08-deferred-transitions/app-b/App.svelte new file mode 100644 index 0000000000..3cb21a8ed9 --- /dev/null +++ b/site/content/tutorial/10-transitions/08-deferred-transitions/app-b/App.svelte @@ -0,0 +1,155 @@ + + +
+ e.which === 13 && add(e.target)} + > + +
+

todo

+ {#each todos.filter(t => !t.done) as todo (todo.id)} + + {/each} +
+ +
+

done

+ {#each todos.filter(t => t.done) as todo (todo.id)} + + {/each} +
+
+ + \ No newline at end of file diff --git a/site/content/tutorial/10-transitions/08-deferred-transitions/text.md b/site/content/tutorial/10-transitions/08-deferred-transitions/text.md new file mode 100644 index 0000000000..49f626554d --- /dev/null +++ b/site/content/tutorial/10-transitions/08-deferred-transitions/text.md @@ -0,0 +1,30 @@ +--- +title: Deferred transitions +--- + +A particularly powerful feature of Svelte's transition engine is the ability to *defer* transitions, so that they can be coordinated between multiple elements. + +Take this pair of todo lists, in which toggling a todo sends it to the opposite list. In the real world, objects don't behave like that — instead of disappearing and reappearing in another place, they move through a series of intermediate positions. Using motion can go a long way towards helping users understand what's happening in your app. + +We can achieve this effect using the `crossfade` function, which creates a pair of transitions called `send` and `receive`. When an element is 'sent', it looks for a corresponding element being 'received', and generates a transition that transforms the element to its counterpart's position and fades it out. When an element is 'received', the reverse happens. If there is no counterpart, the `fallback` transition is used. + +Find the `