diff --git a/site/content/tutorial/08-stores/01-writable-stores/app-a/App.svelte b/site/content/tutorial/08-stores/01-writable-stores/app-a/App.svelte index ee542f789d..f2a4023f25 100644 --- a/site/content/tutorial/08-stores/01-writable-stores/app-a/App.svelte +++ b/site/content/tutorial/08-stores/01-writable-stores/app-a/App.svelte @@ -6,7 +6,7 @@ let count_value; - const unsubscribe = count.subscribe(value => { + count.subscribe(value => { count_value = value; }); @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/site/content/tutorial/08-stores/01-writable-stores/text.md b/site/content/tutorial/08-stores/01-writable-stores/text.md index 57c27411ea..247ef86e8d 100644 --- a/site/content/tutorial/08-stores/01-writable-stores/text.md +++ b/site/content/tutorial/08-stores/01-writable-stores/text.md @@ -24,4 +24,4 @@ Finally, in `Resetter.svelte`, implement `reset`: function reset() { count.set(0); } -``` \ No newline at end of file +``` diff --git a/site/content/tutorial/08-stores/02-auto-subscriptions/app-a/App.svelte b/site/content/tutorial/08-stores/02-auto-subscriptions/app-a/App.svelte index ee542f789d..f2a4023f25 100644 --- a/site/content/tutorial/08-stores/02-auto-subscriptions/app-a/App.svelte +++ b/site/content/tutorial/08-stores/02-auto-subscriptions/app-a/App.svelte @@ -6,7 +6,7 @@ let count_value; - const unsubscribe = count.subscribe(value => { + count.subscribe(value => { count_value = value; }); @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/site/content/tutorial/08-stores/02-auto-subscriptions/text.md b/site/content/tutorial/08-stores/02-auto-subscriptions/text.md index af584261f4..f80c4b2f72 100644 --- a/site/content/tutorial/08-stores/02-auto-subscriptions/text.md +++ b/site/content/tutorial/08-stores/02-auto-subscriptions/text.md @@ -2,9 +2,17 @@ title: Auto-subscriptions --- -The app in the previous example works, but there's a subtle bug — the `unsubscribe` function never gets called. If the component was instantiated and destroyed many times, this would result in a *memory leak*. +The app in the previous example works, but there's a subtle bug — the store is subscribed to, but never unsubscribed. If the component was instantiated and destroyed many times, this would result in a *memory leak*. -One way to fix it would be to use the `onDestroy` [lifecycle hook](tutorial/ondestroy): +Start by declaring `unsubscribe` in `App.svelte`: + +```js +const unsubscribe = count.subscribe(value => { + count_value = value; +}); +``` + +You now declared `unsubscribe`, but it still needs be to called, for example through the `onDestroy` [lifecycle hook](tutorial/ondestroy): ```html