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 11import Vue from 'vue'
2- import Vuex from '../../../src '
2+ import Vuex from 'vuex '
33import * as getters from './getters'
44import * as actions from './actions'
55import * as mutations from './mutations'
Original file line number Diff line number Diff line change 99 autofocus
1010 autocomplete =" off"
1111 placeholder =" What needs to be done?"
12- @keyup.enter =" tryAddTodo " >
12+ @keyup.enter =" addTodo " >
1313 </header >
1414 <!-- main section -->
1515 <section class =" main" v-show =" todos.length" >
4646</template >
4747
4848<script >
49+ import { mapActions } from ' vuex'
4950import Todo from ' ./Todo.vue'
50- import {
51- addTodo ,
52- toggleAll ,
53- clearCompleted
54- } from ' ../vuex/actions'
5551
5652const filters = {
5753 all : todos => todos,
@@ -61,23 +57,16 @@ const filters = {
6157
6258export default {
6359 components: { Todo },
64- vuex: {
65- getters: {
66- todos : state => state .todos
67- },
68- actions: {
69- addTodo,
70- toggleAll,
71- clearCompleted
72- }
73- },
7460 data () {
7561 return {
7662 visibility: ' all' ,
7763 filters: filters
7864 }
7965 },
8066 computed: {
67+ todos () {
68+ return this .$store .state .todos
69+ },
8170 allChecked () {
8271 return this .todos .every (todo => todo .done )
8372 },
@@ -89,13 +78,17 @@ export default {
8978 }
9079 },
9180 methods: {
92- tryAddTodo (e ) {
81+ addTodo (e ) {
9382 var text = e .target .value
9483 if (text .trim ()) {
95- this .addTodo ( text)
84+ this .$store . call ( ' addTodo ' , text)
9685 }
9786 e .target .value = ' '
98- }
87+ },
88+ ... mapActions ([
89+ ' toggleAll' ,
90+ ' clearCompleted'
91+ ])
9992 },
10093 filters: {
10194 pluralize : (n , w ) => n === 1 ? w : (w + ' s' ),
Original file line number Diff line number Diff line change 1919</template >
2020
2121<script >
22- import {
23- toggleTodo ,
24- deleteTodo ,
25- editTodo
26- } from ' ../vuex/actions'
27-
2822export default {
2923 props: [' todo' ],
30- vuex: {
31- actions: {
32- toggleTodo,
33- deleteTodo,
34- editTodo
35- }
36- },
3724 data () {
3825 return {
3926 editing: false
@@ -49,12 +36,15 @@ export default {
4936 }
5037 },
5138 methods: {
39+ toggleTodo (todo ) {
40+ this .$store .call (' toggleTodo' , todo)
41+ },
5242 doneEdit (e ) {
5343 const value = e .target .value .trim ()
5444 if (! value) {
55- this .deleteTodo ( this .todo )
45+ this .$store . call ( ' deleteTodo ' , this .todo )
5646 } else if (this .editing ) {
57- this .editTodo ( this .todo , value)
47+ this .$store . call ( ' editTodo ' , this .todo , value)
5848 this .editing = false
5949 }
6050 },
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { STORAGE_KEY } from './store'
22import createLogger from '../../../src/plugins/logger'
33
44const localStoragePlugin = store => {
5- store . on ( 'mutation' , ( mutation , { todos } ) => {
5+ store . subscribe ( ( mutation , { todos } ) => {
66 localStorage . setItem ( STORAGE_KEY , JSON . stringify ( todos ) )
77 } )
88}
Original file line number Diff line number Diff line change 11import Vue from 'vue'
2- import Vuex from '../../../src '
2+ import Vuex from 'vuex '
33import plugins from './plugins'
4+ import * as actions from './actions'
45
56Vue . use ( Vuex )
67
@@ -48,6 +49,7 @@ const mutations = {
4849
4950export default new Vuex . Store ( {
5051 state,
52+ actions,
5153 mutations,
5254 plugins
5355} )
You can’t perform that action at this time.
0 commit comments