File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 33 import AddTodoItem from ' ./AddTodoItem.svelte'
44 import TodoItem from ' ./TodoItem.svelte'
55 import { todoItems , mousePosition } from ' ./store'
6+ import { todoStats } from ' ./todoStatsStore'
67
7- $: count = $todoItems .length ;
8- $: checkedCount = $todoItems .filter (({ checked }) => checked).length
9-
108 function handleAddTodoItem (event ) {
119 todoItems .update (items => [... items, {
1210 id: uuid (),
2927<p >{JSON .stringify ($mousePosition , null , 2 )}</p >
3028<AddTodoItem
3129 title =' Please type todo here:'
32- buttonTitle ={` Add (${checkedCount }/${count }) ` }
30+ buttonTitle ={` Add (${$todoStats . doneCount }/${$todoStats . totalCount }) ` }
3331 on:add ={handleAddTodoItem }
3432/>
3533
36- {#if count === 0 }
34+ {#if $todoStats . totalCount === 0 }
3735 No items yet
3836{:else }
3937 <div >
Original file line number Diff line number Diff line change 1+ import { derived } from 'svelte/store'
2+ import { todoItems } from './store'
3+
4+ export const todoStats = derived (
5+ [ todoItems ] ,
6+ ( [ todoItems ] ) => {
7+ const doneCount = todoItems . filter ( item => item . checked ) . length
8+ const totalCount = todoItems . length
9+ return {
10+ doneCount,
11+ totalCount,
12+ leftTodoCount : totalCount - doneCount
13+ }
14+ }
15+ )
You can’t perform that action at this time.
0 commit comments