File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 11<script >
2+ import { onMount } from ' svelte'
23 import { v4 as uuid } from ' uuid'
34 import AddTodoItem from ' ./AddTodoItem.svelte'
45 import TodoItem from ' ./TodoItem.svelte'
6+ import getTodos from ' ./getTodos'
7+ import { onInterval } from ' ./interval'
58
6- let items = [{
7- id: uuid (),
8- text: ' First Item' ,
9- done: false ,
10- }, {
11- id: uuid (),
12- text: ' Second Item' ,
13- checked: true ,
14- }]
9+ let items = []
10+ let counter = 0
1511 $: count = items .length ;
1612 $: checkedCount = items .filter (({ checked }) => checked).length
13+
14+ onInterval (() => {
15+ counter++
16+ }, 1000 )
17+
18+ onMount (async () => {
19+ items = await getTodos ()
20+ })
1721
1822 function handleAddTodoItem (event ) {
1923 items = [... items, {
3438 }
3539 </script >
3640
41+ <p >{counter }</p >
3742<AddTodoItem
3843 title =' Please type todo here:'
3944 buttonTitle ={` Add (${checkedCount }/${count }) ` }
Original file line number Diff line number Diff line change 1+ import { onDestroy } from 'svelte'
2+
3+ export function onInterval ( cb , ms ) {
4+ const interval = setInterval ( cb , ms )
5+ onDestroy ( ( ) => {
6+ clearInterval ( interval )
7+ } )
8+ }
You can’t perform that action at this time.
0 commit comments