Skip to content

Commit 31aeae7

Browse files
committed
update API docs
1 parent 977ee4a commit 31aeae7

File tree

1 file changed

+64
-24
lines changed

1 file changed

+64
-24
lines changed

docs/en/api.md

+64-24
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,40 @@ const store = new Vuex.Store({ ...options })
2020

2121
- **mutations**
2222

23-
- type: `Object`
23+
- type: `{ [type: string]: Function }`
2424

25-
An object where each entry's key is the mutation name and the value is a mutation handler function. The handler function always receives `state` as the first argument, and receives all arguments passed to the dispatch call following that.
25+
Register mutations on the store. The handler function always receives `state` as the first argument (will be module local state if defined in a module), and receives a second `payload` argument if there is one.
2626

2727
[Details](mutations.md)
2828

29+
- **actions**
30+
31+
- type: `{ [type: string]: Function }`
32+
33+
Register actions on the store. The handler function receives a `context` object that exposes the following properties:
34+
35+
``` js
36+
{
37+
state, // same as store.state, or local state if in modules
38+
rootState, // same as store.state, only in modules
39+
commit, // same as store.commit
40+
dispatch, // same as store.dispatch
41+
getters // same as store.getters
42+
}
43+
```
44+
45+
[Details](actions.md)
46+
47+
- **getters**
48+
49+
- type: `{ [key: string]: Function }`
50+
51+
Register getters on the store. The getter function receives the `state` as the first argument (will be module local state if defined in a module).
52+
53+
Registered getters are exposed on `store.getters`.
54+
55+
[Details](getters.md)
56+
2957
- **modules**
3058

3159
- type: `Object`
@@ -36,13 +64,18 @@ const store = new Vuex.Store({ ...options })
3664
{
3765
key: {
3866
state,
39-
mutations
67+
mutations,
68+
actions?,
69+
getters?,
70+
modules?
4071
},
4172
...
4273
}
4374
```
4475
45-
Each module can contain `state` and `mutations` similar to the root options. A module's state will be attached to the store's root state using the module's key. A module's mutations will only receives the module's own state as the first argument instead of the root state.
76+
Each module can contain `state` and `mutations` similar to the root options. A module's state will be attached to the store's root state using the module's key. A module's mutations and getters will only receives the module's local state as the first argument instead of the root state, and module actions' `context.state` will also point to the local state.
77+
78+
[Details](modules.md)
4679
4780
- **plugins**
4881
@@ -69,40 +102,33 @@ const store = new Vuex.Store({ ...options })
69102
70103
The root state. Read only.
71104
72-
### Vuex.Store Instance Methods
105+
- **getters**
73106
74-
- **dispatch(mutationName: String, ...args) | dispatch(mutation: Object)**
107+
- type: `Object`
75108
76-
Directly dispatch a mutation. This is useful in certain situations are in general you should prefer using actions in application code.
109+
Exposes registered getters. Read only.
77110
78-
*Object-Style Dispatch*
111+
### Vuex.Store Instance Methods
79112
80-
> requires >=0.6.2
113+
- **`commit(type: string, payload?: any) | commit(mutation: Object)`**
81114
82-
You can also dispatch mutations using objects:
115+
Commit a mutation. [Details](mutations.md)
83116
84-
``` js
85-
store.dispatch({
86-
type: 'INCREMENT',
87-
payload: 10
88-
})
89-
```
117+
- **`dispatch(type: string, payload?: any) | dispatch(action: Object)`**
90118
91-
- **replaceState(state: Object)**
119+
Dispatch an action. Returns the return value of the triggered action handler, or a Promise if multiple handlers are triggered. [Details](actions.md)
92120
93-
Replace the store's root state. Use this only for state restoration / time-travel purposes.
121+
- **`replaceState(state: Object)`**
94122
95-
- **watch(getter: Function, cb: Function, [options: Object])**
123+
Replace the store's root state. Use this only for state hydration / time-travel purposes.
124+
125+
- **`watch(getter: Function, cb: Function, options?: Object)`**
96126
97127
Reactively watch a getter function's return value, and call the callback when the value changes. The getter receives the store's state as the only argument. Accepts an optional options object that takes the same options as Vue's `vm.$watch` method.
98128
99129
To stop watching, call the returned handle function.
100130
101-
- **hotUpdate(newOptions: Object)**
102-
103-
Hot swap new actions and mutations. [Details](hot-reload.md)
104-
105-
- **subscribe(handler: Function)**
131+
- **`subscribe(handler: Function)`**
106132
107133
Subscribe to store mutations. The `handler` is called after every mutaiton and receives the mutation descriptor and post-mutation state as arguments:
108134
@@ -112,3 +138,17 @@ const store = new Vuex.Store({ ...options })
112138
console.log(mutation.payload)
113139
})
114140
```
141+
142+
Most commonly used in plugins. [Details](plugins.md)
143+
144+
- **`registerModule(path: string | Array<string>, module: Module)`**
145+
146+
Register a dynamic module. [Details](modules.md#dynamic-module-registration)
147+
148+
- **`unregisterModule(path: string | Array<string>)`**
149+
150+
Unregister a dynamic module. [Details](modules.md#dynamic-module-registration)
151+
152+
- **`hotUpdate(newOptions: Object)`**
153+
154+
Hot swap new actions and mutations. [Details](hot-reload.md)

0 commit comments

Comments
 (0)