File tree Expand file tree Collapse file tree 5 files changed +22
-37
lines changed Expand file tree Collapse file tree 5 files changed +22
-37
lines changed Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
- import Vuex from '../../../src '
2
+ import Vuex from 'vuex '
3
3
import * as getters from './getters'
4
4
import * as actions from './actions'
5
5
import * as mutations from './mutations'
Original file line number Diff line number Diff line change 9
9
autofocus
10
10
autocomplete =" off"
11
11
placeholder =" What needs to be done?"
12
- @keyup.enter =" tryAddTodo " >
12
+ @keyup.enter =" addTodo " >
13
13
</header >
14
14
<!-- main section -->
15
15
<section class =" main" v-show =" todos.length" >
46
46
</template >
47
47
48
48
<script >
49
+ import { mapActions } from ' vuex'
49
50
import Todo from ' ./Todo.vue'
50
- import {
51
- addTodo ,
52
- toggleAll ,
53
- clearCompleted
54
- } from ' ../vuex/actions'
55
51
56
52
const filters = {
57
53
all : todos => todos,
@@ -61,23 +57,16 @@ const filters = {
61
57
62
58
export default {
63
59
components: { Todo },
64
- vuex: {
65
- getters: {
66
- todos : state => state .todos
67
- },
68
- actions: {
69
- addTodo,
70
- toggleAll,
71
- clearCompleted
72
- }
73
- },
74
60
data () {
75
61
return {
76
62
visibility: ' all' ,
77
63
filters: filters
78
64
}
79
65
},
80
66
computed: {
67
+ todos () {
68
+ return this .$store .state .todos
69
+ },
81
70
allChecked () {
82
71
return this .todos .every (todo => todo .done )
83
72
},
@@ -89,13 +78,17 @@ export default {
89
78
}
90
79
},
91
80
methods: {
92
- tryAddTodo (e ) {
81
+ addTodo (e ) {
93
82
var text = e .target .value
94
83
if (text .trim ()) {
95
- this .addTodo ( text)
84
+ this .$store . call ( ' addTodo ' , text)
96
85
}
97
86
e .target .value = ' '
98
- }
87
+ },
88
+ ... mapActions ([
89
+ ' toggleAll' ,
90
+ ' clearCompleted'
91
+ ])
99
92
},
100
93
filters: {
101
94
pluralize : (n , w ) => n === 1 ? w : (w + ' s' ),
Original file line number Diff line number Diff line change 19
19
</template >
20
20
21
21
<script >
22
- import {
23
- toggleTodo ,
24
- deleteTodo ,
25
- editTodo
26
- } from ' ../vuex/actions'
27
-
28
22
export default {
29
23
props: [' todo' ],
30
- vuex: {
31
- actions: {
32
- toggleTodo,
33
- deleteTodo,
34
- editTodo
35
- }
36
- },
37
24
data () {
38
25
return {
39
26
editing: false
@@ -49,12 +36,15 @@ export default {
49
36
}
50
37
},
51
38
methods: {
39
+ toggleTodo (todo ) {
40
+ this .$store .call (' toggleTodo' , todo)
41
+ },
52
42
doneEdit (e ) {
53
43
const value = e .target .value .trim ()
54
44
if (! value) {
55
- this .deleteTodo ( this .todo )
45
+ this .$store . call ( ' deleteTodo ' , this .todo )
56
46
} else if (this .editing ) {
57
- this .editTodo ( this .todo , value)
47
+ this .$store . call ( ' editTodo ' , this .todo , value)
58
48
this .editing = false
59
49
}
60
50
},
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { STORAGE_KEY } from './store'
2
2
import createLogger from '../../../src/plugins/logger'
3
3
4
4
const localStoragePlugin = store => {
5
- store . on ( 'mutation' , ( mutation , { todos } ) => {
5
+ store . subscribe ( ( mutation , { todos } ) => {
6
6
localStorage . setItem ( STORAGE_KEY , JSON . stringify ( todos ) )
7
7
} )
8
8
}
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
- import Vuex from '../../../src '
2
+ import Vuex from 'vuex '
3
3
import plugins from './plugins'
4
+ import * as actions from './actions'
4
5
5
6
Vue . use ( Vuex )
6
7
@@ -48,6 +49,7 @@ const mutations = {
48
49
49
50
export default new Vuex . Store ( {
50
51
state,
52
+ actions,
51
53
mutations,
52
54
plugins
53
55
} )
You can’t perform that action at this time.
0 commit comments