File tree Expand file tree Collapse file tree 3 files changed +9
-16
lines changed
Expand file tree Collapse file tree 3 files changed +9
-16
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ <h1>todos</h1>
3939 class ="toggle "
4040 type ="checkbox "
4141 v-model ="completed "
42- v-on ="change: toggleTodo(this) "
4342 >
4443 < label v-text ="title " v-on ="dblclick: editTodo(this) "> </ label >
4544 < button class ="destroy " v-on ="click: removeTodo(this) "> </ button >
Original file line number Diff line number Diff line change 2929 filter : 'all'
3030 } ,
3131
32+ // ready hook, watch todos change for data persistence
33+ ready : function ( ) {
34+ this . $watch ( 'todos' , function ( todos ) {
35+ todoStorage . save ( todos ) ;
36+ } ) ;
37+ } ,
38+
3239 // a custom directive to wait for the DOM to be updated
3340 // before focusing on the input field.
3441 // http://vuejs.org/guide/directives.html#Writing_a_Custom_Directive
6471 this . todos . forEach ( function ( todo ) {
6572 todo . completed = value ;
6673 } ) ;
67- todoStorage . save ( ) ;
6874 }
6975 }
7076 } ,
8086 }
8187 this . todos . push ( { title : value , completed : false } ) ;
8288 this . newTodo = '' ;
83- todoStorage . save ( ) ;
8489 } ,
8590
8691 removeTodo : function ( todo ) {
8792 this . todos . $remove ( todo . $data ) ;
88- todoStorage . save ( ) ;
89- } ,
90-
91- toggleTodo : function ( todo ) {
92- todoStorage . save ( ) ;
9393 } ,
9494
9595 editTodo : function ( todo ) {
106106 if ( ! todo . title ) {
107107 this . removeTodo ( todo ) ;
108108 }
109- todoStorage . save ( ) ;
110109 } ,
111110
112111 cancelEdit : function ( todo ) {
116115
117116 removeCompleted : function ( ) {
118117 this . todos = this . todos . filter ( filters . active ) ;
119- todoStorage . save ( ) ;
120118 }
121119 }
122120 } ) ;
Original file line number Diff line number Diff line change 55 'use strict' ;
66
77 var STORAGE_KEY = 'todos-vuejs' ;
8- var todos = null ;
98
109 exports . todoStorage = {
1110 fetch : function ( ) {
12- if ( ! todos ) {
13- todos = JSON . parse ( localStorage . getItem ( STORAGE_KEY ) || '[]' ) ;
14- }
15- return todos ;
11+ return JSON . parse ( localStorage . getItem ( STORAGE_KEY ) || '[]' ) ;
1612 } ,
17- save : function ( ) {
13+ save : function ( todos ) {
1814 localStorage . setItem ( STORAGE_KEY , JSON . stringify ( todos ) ) ;
1915 }
2016 } ;
You can’t perform that action at this time.
0 commit comments