Skip to content

Commit adaa2c3

Browse files
committed
update todomvc example to use store injection
1 parent 5fe5305 commit adaa2c3

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

examples/todomvc/components/App.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,8 @@
4646
</template>
4747

4848
<script>
49-
import store from '../store'
5049
import Todo from './Todo.vue'
5150
52-
const {
53-
addTodo,
54-
toggleAll,
55-
clearCompleted
56-
} = store.actions
57-
5851
const filters = {
5952
all: (todos) => todos,
6053
active: (todos) => todos.filter(todo => !todo.done),
@@ -71,7 +64,7 @@ export default {
7164
},
7265
computed: {
7366
todos () {
74-
return store.state.todos
67+
return this.$store.state.todos
7568
},
7669
allChecked () {
7770
return this.todos.every(todo => todo.done)
@@ -87,12 +80,16 @@ export default {
8780
addTodo (e) {
8881
var text = e.target.value
8982
if (text.trim()) {
90-
addTodo(text)
83+
this.$store.actions.addTodo(text)
9184
}
9285
e.target.value = ''
9386
},
94-
toggleAll,
95-
clearCompleted
87+
toggleAll () {
88+
this.$store.actions.toggleAll()
89+
},
90+
clearCompleted () {
91+
this.$store.actions.clearCompleted()
92+
}
9693
}
9794
}
9895
</script>

examples/todomvc/components/Todo.vue

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
</template>
2020

2121
<script>
22-
import store from '../store'
23-
const {
24-
toggleTodo,
25-
deleteTodo,
26-
editTodo
27-
} = store.actions
28-
2922
export default {
3023
props: ['todo'],
3124
data () {
@@ -43,14 +36,18 @@ export default {
4336
}
4437
},
4538
methods: {
46-
toggleTodo,
47-
deleteTodo,
39+
toggleTodo (todo) {
40+
this.$store.actions.toggleTodo(todo)
41+
},
42+
deleteTodo (todo) {
43+
this.$store.actions.deleteTodo(todo)
44+
},
4845
doneEdit (e) {
49-
var value = e.target.value.trim()
46+
const value = e.target.value.trim()
5047
if (!value) {
51-
deleteTodo(this.todo)
48+
this.deleteTodo(this.todo)
5249
} else if (this.editing) {
53-
editTodo(this.todo, value)
50+
this.editTodo(this.todo, value)
5451
this.editing = false
5552
}
5653
},

examples/todomvc/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Vue from 'vue'
2+
import store from './store'
23
import App from './components/App.vue'
34

45
new Vue({
6+
store, // inject store to all children
57
el: 'body',
68
components: { App }
79
})

0 commit comments

Comments
 (0)