@@ -3,7 +3,9 @@ import { v4 as uuid } from 'node-uuid';
3
3
4
4
export const initialState = {
5
5
items : [
6
- { id : uuid ( ) , name : 'Check the other example' , done : false }
6
+ { id : uuid ( ) , name : 'Open Todo list example' , done : true } ,
7
+ { id : uuid ( ) , name : 'Check the other examples' , done : false } ,
8
+ { id : uuid ( ) , name : 'Use Angular ngRx Material Starter in your project' , done : false }
7
9
] ,
8
10
filter : 'ALL'
9
11
} ;
@@ -15,10 +17,12 @@ export const TODOS_ADD = 'TODOS_ADD';
15
17
export const TODOS_TOGGLE = 'TODOS_TOGGLE' ;
16
18
export const TODOS_REMOVE_DONE = 'TODOS_REMOVE_DONE' ;
17
19
export const TODOS_FILTER = 'TODOS_FILTER' ;
20
+ export const TODOS_PERSIST = 'TODOS_PERSIST' ;
18
21
19
22
export const addTodo = ( name : string ) => ( { type : TODOS_ADD , payload : name } ) ;
20
23
export const toggleTodo = ( id : string ) => ( { type : TODOS_TOGGLE , payload : id } ) ;
21
24
export const removeDoneTodos = ( ) => ( { type : TODOS_REMOVE_DONE } ) ;
25
+ export const persistTodos = ( todos ) => ( { type : TODOS_PERSIST , payload : todos } ) ;
22
26
export const filterTodos = ( filter : TodoFilter ) =>
23
27
( { type : TODOS_FILTER , payload : filter } ) ;
24
28
@@ -31,7 +35,7 @@ export function todosReducer(state = initialState, action: Action) {
31
35
} ) ;
32
36
33
37
case TODOS_TOGGLE :
34
- state . items . some ( ( item : any ) => {
38
+ state . items . some ( ( item : Todo ) => {
35
39
if ( item . id === action . payload ) {
36
40
item . done = ! item . done ;
37
41
return true ;
@@ -43,7 +47,7 @@ export function todosReducer(state = initialState, action: Action) {
43
47
44
48
case TODOS_REMOVE_DONE :
45
49
return Object . assign ( { } , state ,
46
- { items : state . items . filter ( ( item : any ) => ! item . done ) } ) ;
50
+ { items : state . items . filter ( ( item : Todo ) => ! item . done ) } ) ;
47
51
48
52
case TODOS_FILTER :
49
53
return Object . assign ( { } , state , { filter : action . payload } ) ;
@@ -53,3 +57,8 @@ export function todosReducer(state = initialState, action: Action) {
53
57
}
54
58
}
55
59
60
+ export interface Todo {
61
+ id : string ;
62
+ name : string ;
63
+ done : boolean ;
64
+ }
0 commit comments