From 80a393cdb21fa5b0d1ac9f6688e806db43d3c61d Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 9 Mar 2019 13:57:18 -0500 Subject: [PATCH] tick chapter --- .../07-lifecycle/04-tick/app-a/App.svelte | 35 ++++++++++++++++++ .../07-lifecycle/04-tick/app-b/App.svelte | 37 +++++++++++++++++++ .../tutorial/07-lifecycle/04-tick/text.md | 21 +++++++++++ site/content/tutorial/99-todo/99-todo/text.md | 5 +-- site/src/routes/tutorial/[slug]/index.svelte | 2 +- 5 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 site/content/tutorial/07-lifecycle/04-tick/app-a/App.svelte create mode 100644 site/content/tutorial/07-lifecycle/04-tick/app-b/App.svelte create mode 100644 site/content/tutorial/07-lifecycle/04-tick/text.md diff --git a/site/content/tutorial/07-lifecycle/04-tick/app-a/App.svelte b/site/content/tutorial/07-lifecycle/04-tick/app-a/App.svelte new file mode 100644 index 0000000000..3386ff93df --- /dev/null +++ b/site/content/tutorial/07-lifecycle/04-tick/app-a/App.svelte @@ -0,0 +1,35 @@ + + + + + \ No newline at end of file diff --git a/site/content/tutorial/07-lifecycle/04-tick/app-b/App.svelte b/site/content/tutorial/07-lifecycle/04-tick/app-b/App.svelte new file mode 100644 index 0000000000..c9cb6de420 --- /dev/null +++ b/site/content/tutorial/07-lifecycle/04-tick/app-b/App.svelte @@ -0,0 +1,37 @@ + + + + + \ No newline at end of file diff --git a/site/content/tutorial/07-lifecycle/04-tick/text.md b/site/content/tutorial/07-lifecycle/04-tick/text.md new file mode 100644 index 0000000000..b58b024ad6 --- /dev/null +++ b/site/content/tutorial/07-lifecycle/04-tick/text.md @@ -0,0 +1,21 @@ +--- +title: tick +--- + +The `tick` function is unlike other lifecycle functions in that you can call it any time, not just when the component first initialises. It returns a promise that resolves as soon as any pending state changes have been applied to the DOM (or immediately, if there are no pending state changes). + +When you invalidate component state in Svelte, it doesn't update the DOM immediately. Instead, it waits until the next *microtask* to see if there are any other changes that need to be applied, including in other components. Doing so avoids unnecessary work and allows the browser to batch things more effectively. + +You can see that behaviour in this example. Select a range of text and hit the tab key. Because the `