Skip to content

Commit d662bf9

Browse files
committed
update vuex
1 parent b267f08 commit d662bf9

File tree

5 files changed

+52
-34
lines changed

5 files changed

+52
-34
lines changed

template/src/components/views/todo/footer/footer.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import template from './footer.vue'
1111

1212
import Filters from '../filter'
1313

14-
import { Store } from 'store/modules/todo'
14+
import { Getter, Mutation } from 'store/modules/todo'
1515

1616
@Component({
1717
name: 'tag-todo-footer',
@@ -21,9 +21,12 @@ import { Store } from 'store/modules/todo'
2121
}
2222
})
2323
export default class Footer extends Vue {
24-
@Store.getter remaining: Types.todo.Item[]
25-
@Store.getter completed: Types.todo.Item[]
24+
@Getter
25+
remaining: Types.todo.Item[]
2626

27-
@Store.mutation
27+
@Getter
28+
completed: Types.todo.Item[]
29+
30+
@Mutation
2831
clearComplete: () => void
2932
}

template/src/components/views/todo/inputBox/inputBox.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Vue from 'components/base'
99
import { Component } from 'vue-property-decorator'
1010
import template from './inputBox.vue'
1111

12-
import { Store } from 'store/modules/todo'
12+
import { State, Getter, Mutation } from 'store/modules/todo'
1313

1414
@Component({
1515
name: 'tag-todo-inputbox',
@@ -18,14 +18,16 @@ import { Store } from 'store/modules/todo'
1818
export default class InputBox extends Vue {
1919
title = ''
2020

21-
@Store.state todos: Types.todo.Item[]
21+
@State
22+
todos: Types.todo.Item[]
2223

23-
@Store.getter isAllCompleted: boolean
24+
@Getter
25+
isAllCompleted: boolean
2426

25-
@Store.mutation
27+
@Mutation
2628
addTodo: (todo: Types.todo.Item) => void
2729

28-
@Store.mutation('toggleAllTodoStatus')
30+
@Mutation('toggleAllTodoStatus')
2931
toggleAllStatus: (status: boolean) => void
3032

3133
onEnter () {

template/src/components/views/todo/item/item.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Vue from 'components/base'
99
import { Component, Prop } from 'vue-property-decorator'
1010
import template from './item.vue'
1111

12-
import { Store } from 'store/modules/todo'
12+
import { Mutation } from 'store/modules/todo'
1313

1414
@Component({
1515
name: 'tag-todo-item',
@@ -19,10 +19,10 @@ export default class Item extends Vue {
1919
@Prop()
2020
todo: Types.todo.Item
2121

22-
@Store.mutation('removeTodo')
22+
@Mutation('removeTodo')
2323
remove: (todo: Types.todo.Item) => void
2424

25-
@Store.mutation('toggleTodoStatus')
25+
@Mutation('toggleTodoStatus')
2626
toggleStatus: (payload: { todo: Types.todo.Item, status: boolean }) => void
2727

2828
get status () {

template/src/components/views/todo/todo.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TodoItem from './item'
1414
import TodoFooter from './footer'
1515

1616
// vuex
17-
import { Store } from 'store/modules/todo'
17+
import { State, Getter, Mutation, Action } from 'store/modules/todo'
1818

1919
@Component({
2020
name: 'view-todo',
@@ -26,15 +26,23 @@ import { Store } from 'store/modules/todo'
2626
}
2727
})
2828
export default class Todo extends Vue {
29-
@Store.state('todos') allTodos: Types.todo.Item[]
29+
@State('todos')
30+
allTodos: Types.todo.Item[]
3031

31-
@Store.getter('filterTodos') todos: Types.todo.Item[]
32+
@Getter('filterTodos')
33+
todos: Types.todo.Item[]
3234

33-
@Store.mutation setFilter: (filter) => void
34-
@Store.mutation clearData: () => void
35+
@Mutation
36+
setFilter: (filter) => void
3537

36-
@Store.action fetch: () => Promise<any>
37-
@Store.action save: () => Promise<any>
38+
@Mutation
39+
clearData: () => void
40+
41+
@Action
42+
fetch: () => Promise<any>
43+
44+
@Action
45+
save: () => Promise<any>
3846

3947
@Watch('todos', {deep: true})
4048
onTodosChange () {

template/src/store/modules/todo.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@
33
*/
44

55
import Vuex from 'vuex'
6-
import { State, Getter, Mutation, Action, namespace } from 'vuex-class'
76
import keymirror from '../utils/keymirror'
8-
import { getter, mutation, action, decorator } from '../utils/vuexUtil'
97

8+
import {
9+
State as vState,
10+
Getter as vGetter,
11+
Mutation as vMutation,
12+
Action as vAction,
13+
namespace
14+
} from 'vuex-class'
15+
16+
import {
17+
getter,
18+
mutation,
19+
action,
20+
decorator
21+
} from '../utils/vuexUtil'
22+
23+
const storeName = 'todo'
1024
const STORE_KEY = 'vue-typescript-todos'
1125

1226
/*** state ***/
@@ -115,18 +129,9 @@ export let types = {
115129
action: keymirror(actions)
116130
}
117131

118-
export let module = {
119-
State: namespace('todo', State),
120-
Getter: namespace('todo', Getter),
121-
Mutation: namespace('todo', Mutation),
122-
Action: namespace('todo', Action)
123-
}
124-
125-
export let Store = {
126-
state: decorator(module.State, types.state),
127-
getter: decorator(module.Getter, types.getter),
128-
mutation: decorator(module.Mutation, types.mutation),
129-
action: decorator(module.Action, types.action),
130-
}
132+
export let State = decorator(namespace(storeName, vState), types.state)
133+
export let Getter = decorator(namespace(storeName, vGetter), types.getter)
134+
export let Mutation = decorator(namespace(storeName, vMutation), types.mutation)
135+
export let Action = decorator(namespace(storeName, vAction), types.action)
131136

132137
export default store

0 commit comments

Comments
 (0)