Skip to content

Commit aab57b2

Browse files
committed
udpate doc
1 parent d662bf9 commit aab57b2

File tree

2 files changed

+65
-45
lines changed

2 files changed

+65
-45
lines changed

docs/en/Vuex.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ export namespace State {
2525

2626
```typescript
2727
import Vuex from 'vuex'
28-
import { State, Getter, Mutation, Action, namespace } from 'vuex-class'
2928
import keymirror from '../utils/keymirror'
3029

31-
// Use vuexUtil methods to write getter, mutation 和 action
32-
import { getter, mutation, action, decorator } from '../utils/vuexUtil'
30+
import {
31+
State as vState,
32+
Getter as vGetter,
33+
Mutation as vMutation,
34+
Action as vAction,
35+
namespace
36+
} from 'vuex-class'
37+
38+
// Use vuexUtil methods to write getter, mutation and action
39+
import {
40+
getter,
41+
mutation,
42+
action,
43+
decorator
44+
} from '../utils/vuexUtil'
45+
3346

3447
/*** state ***/
3548
let state: TodoState = {}
@@ -66,19 +79,12 @@ export let types = {
6679
action: keymirror(actions)
6780
}
6881

69-
export let module = {
70-
State: namespace('todo', State),
71-
Getter: namespace('todo', Getter),
72-
Mutation: namespace('todo', Mutation),
73-
Action: namespace('todo', Action)
74-
}
7582

76-
export let Store = {
77-
state: decorator(module.State, types.state),
78-
getter: decorator(module.Getter, types.getter),
79-
mutation: decorator(module.Mutation, types.mutation),
80-
action: decorator(module.Action, types.action),
81-
}
83+
const storeName = 'todo'
84+
export let State = decorator(namespace(storeName, vState), types.state)
85+
export let Getter = decorator(namespace(storeName, vGetter), types.getter)
86+
export let Mutation = decorator(namespace(storeName, vMutation), types.mutation)
87+
export let Action = decorator(namespace(storeName, vAction), types.action)
8288

8389
export default store
8490
```
@@ -99,20 +105,23 @@ const store = new Vuex.Store({
99105
### Use in components
100106

101107
```typescript
102-
import { Store } from 'store/modules/todo'
108+
import { State, Getter, Mutation, Action } from 'store/modules/todo'
103109

104110
class Todo extends Vue {
105-
@Store.state('todos') allTodos: Types.todo.Item[]
111+
@State('todos')
112+
allTodos: Types.todo.Item[]
106113

107-
// == @Store.state('foo') foo: string
108-
@Store.state foo: string
114+
// == @State('foo') foo: string
115+
@State
116+
foo: string
109117

110-
@Store.getter('filterTodos') todos: Types.todo.Item[]
118+
@Getter('filterTodos')
119+
todos: Types.todo.Item[]
111120

112-
@Store.mutation
121+
@Mutation
113122
filterTodos: (filter: string) => void
114123

115-
@Store.action
124+
@Action
116125
fetch: () => Promise<any>
117126
}
118127
```

docs/zh-cn/Vuex.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ export namespace State {
2525

2626
```typescript
2727
import Vuex from 'vuex'
28-
import { State, Getter, Mutation, Action, namespace } from 'vuex-class'
2928
import keymirror from '../utils/keymirror'
3029

31-
// 使用 vuexUtil 提供的方法编写 getter, mutation 和 action
32-
import { getter, mutation, action, decorator } from '../utils/vuexUtil'
30+
import {
31+
State as vState,
32+
Getter as vGetter,
33+
Mutation as vMutation,
34+
Action as vAction,
35+
namespace
36+
} from 'vuex-class'
37+
38+
// Use vuexUtil methods to write getter, mutation and action
39+
import {
40+
getter,
41+
mutation,
42+
action,
43+
decorator
44+
} from '../utils/vuexUtil'
45+
3346

3447
/*** state ***/
3548
let state: TodoState = {}
@@ -66,21 +79,15 @@ export let types = {
6679
action: keymirror(actions)
6780
}
6881

69-
export let module = {
70-
State: namespace('todo', State),
71-
Getter: namespace('todo', Getter),
72-
Mutation: namespace('todo', Mutation),
73-
Action: namespace('todo', Action)
74-
}
7582

76-
export let Store = {
77-
state: decorator(module.State, types.state),
78-
getter: decorator(module.Getter, types.getter),
79-
mutation: decorator(module.Mutation, types.mutation),
80-
action: decorator(module.Action, types.action),
81-
}
83+
const storeName = 'todo'
84+
export let State = decorator(namespace(storeName, vState), types.state)
85+
export let Getter = decorator(namespace(storeName, vGetter), types.getter)
86+
export let Mutation = decorator(namespace(storeName, vMutation), types.mutation)
87+
export let Action = decorator(namespace(storeName, vAction), types.action)
8288

8389
export default store
90+
8491
```
8592

8693
### 在主 store 中加入该模块
@@ -100,22 +107,26 @@ const store = new Vuex.Store({
100107

101108
```typescript
102109
// vuex
103-
import { Store } from 'store/modules/todo'
110+
import { State, Getter, Mutation, Action } from 'store/modules/todo'
104111

105112
class Todo extends Vue {
106-
@Store.state('todos') allTodos: Types.todo.Item[]
113+
@State('todos')
114+
allTodos: Types.todo.Item[]
107115

108-
// == @Store.state('foo') foo: string
109-
@Store.state foo: string
116+
// == @State('foo') foo: string
117+
@State
118+
foo: string
110119

111-
@Store.getter('filterTodos') todos: Types.todo.Item[]
120+
@Getter('filterTodos')
121+
todos: Types.todo.Item[]
112122

113-
@Store.mutation
123+
@Mutation
114124
filterTodos: (filter: string) => void
115125

116-
@Store.action
126+
@Action
117127
fetch: () => Promise<any>
118128
}
129+
119130
```
120-
建议 state,getter, mutation, action 需要明确写出其类型。
131+
建议 state, getter, mutation, action 需要明确写出其类型。
121132

0 commit comments

Comments
 (0)