Skip to content

Commit 696ce26

Browse files
committed
tweak todomvc example
1 parent dd986f6 commit 696ce26

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

examples/todomvc/js/app.js

+23-20
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,21 @@
2525
// the root element that will be compiled
2626
el: '.todoapp',
2727

28-
// app state data
28+
// app initial state
2929
data: {
3030
todos: todoStorage.fetch(),
3131
newTodo: '',
3232
editedTodo: null,
3333
visibility: 'all'
3434
},
3535

36-
// ready hook, watch todos change for data persistence
37-
ready: function () {
38-
this.$watch('todos', function (todos) {
39-
todoStorage.save(todos);
40-
}, { deep: true });
41-
},
42-
43-
// a custom directive to wait for the DOM to be updated
44-
// before focusing on the input field.
45-
// http://vuejs.org/guide/directives.html#Writing_a_Custom_Directive
46-
directives: {
47-
'todo-focus': function (value) {
48-
if (!value) {
49-
return;
50-
}
51-
var el = this.el;
52-
setTimeout(function () {
53-
el.focus();
54-
}, 0);
36+
// watch todos change for localStorage persistence
37+
watch: {
38+
todos: {
39+
handler: function (todos) {
40+
todoStorage.save(todos);
41+
},
42+
deep: true
5543
}
5644
},
5745

@@ -117,6 +105,21 @@
117105
removeCompleted: function () {
118106
this.todos = filters.active(this.todos);
119107
}
108+
},
109+
110+
// a custom directive to wait for the DOM to be updated
111+
// before focusing on the input field.
112+
// http://vuejs.org/guide/custom-directive.html
113+
directives: {
114+
'todo-focus': function (value) {
115+
if (!value) {
116+
return;
117+
}
118+
var el = this.el;
119+
Vue.nextTick(function () {
120+
el.focus();
121+
});
122+
}
120123
}
121124
});
122125

0 commit comments

Comments
 (0)