Skip to content

Commit 6b6a71b

Browse files
committed
Updated Readme
1 parent 4e33f59 commit 6b6a71b

File tree

1 file changed

+114
-4
lines changed

1 file changed

+114
-4
lines changed

README.md

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ Vuex+ is an opinionated library that makes Vuex module instances possible.
99

1010
**Enhancements:**
1111
- Dynamic root level module instances that can be shared across components
12-
- Root level instances can be persisted or cleared when components are destroyed
13-
- Module states are decorated with a `$parent`-state getter
12+
- Instances get their Vuex path extended with their instance name
13+
`foo` with instance `bar`, becomes `foo$bar`
14+
- Root level instances can be preserved or cleared when components are destroyed
15+
- Module states are decorated with a `$parent`-state object getter
1416
- Yes, still serializable states
1517
- Yes, still injectable states through devtools
1618
- Static submodule instances
17-
- Components bound to submodules know in which statetree they belong
18-
- Vuex+ mapGetters and mapActions expand to full path
19+
- `Vuex+` map.getters and map.actions expand module paths to full paths when component nesting order is same as vuex module nesting order
1920
- Automatic Vuex HMR (needs naming conventions)
2021
- Modules are automatically get `name` and `namespaced` parameters set
2122
- Works side by side with normal vuex
@@ -35,6 +36,115 @@ Check out the extensive tutorial bundled with the example:
3536
- Vuex module filenames
3637
- Vuex submodule filenames
3738

39+
40+
## Exported properties
41+
42+
**Used in `main.js`:**
43+
- `default`:
44+
```javascript
45+
import Vue from 'vue';
46+
import Vuex from 'vuex';
47+
import VuexPlus from 'vuex-plus';
48+
49+
Vue.use(Vuex);
50+
Vue.use(VuexPlus.getVuePlugin(Vue)); // Adds global vuex+ mixin to components
51+
52+
const store = new Vuex.Store({
53+
plugins: [VuexPlus.getVuexPlugin(Vuex)], // Patch vuex for $parent & bootstrap HMR
54+
});
55+
56+
new Vue({
57+
el: '#app',
58+
store,
59+
render: h => h(require('./app.vue')), // Start application
60+
});
61+
```
62+
63+
---
64+
65+
**Used in vuex modules:**
66+
- `store`: Method used to wrap Vuex module definitions to make them into `Vuex+ modules`
67+
```javascript
68+
import { store } from 'vuex-plus';
69+
export default store({
70+
state,
71+
getters,
72+
...
73+
});
74+
```
75+
- `newInstance`: Wrapper to make new submodule instance
76+
```javascript
77+
import { store, newInstance } from 'vuex-plus';
78+
import submodule from './a-submodule.js';
79+
80+
const submodule$foo = newInstance(submodule, 'foo');
81+
const submodule$bar = newInstance(submodule, 'bar');
82+
83+
export default store({
84+
modules: {
85+
submodule$foo,
86+
submodule$bar,
87+
},
88+
});
89+
```
90+
91+
- `root`: Object used for easy access to various application getters/actions.
92+
```javascript
93+
import { root } from 'vuex-plus';
94+
```
95+
- Use paths with absolute path to reach anywhere in the application.
96+
```javascript
97+
root.get{ path: 'a/b$foo/someGetter' };
98+
root.dispatch{ path: 'c$foo/d$bar/someAction', data: 42 };
99+
```
100+
- Use together with `context.state` for easy access in the same instance tree. Two path keywords expands to path within the instance:
101+
- `'$root'` - Expands to root the level root level module with its instance
102+
```javascript
103+
root.get({ path: '$root/someGetter', state: context.state });
104+
// expands to root.get({ path: 'a/someGetter' });
105+
```
106+
- `'$parent'` - Expands to the parent module with all instances needed
107+
```javascript
108+
root.get({ path: '$parent/someGetter', state: context.state });
109+
// expands to root.get({ path: 'a/b$foo/someGetter' });
110+
```
111+
112+
---
113+
114+
**Used in components:**
115+
- `root`: Same as above, but only absolute paths work
116+
- `map`: `Vuex+` own version of `mapGetters`/`mapActions` with module namespacing handled, when that the component tree and their vuex models are nested in the same way.
117+
If vuex modules are nested like so
118+
```
119+
a
120+
b$chuu
121+
c
122+
```
123+
The vuex modules mapping them, needs the same order, even if other components can be squeezed in between:
124+
```
125+
A(a) // Mapping a
126+
Foo
127+
B(b) // Mapping b
128+
Bar
129+
Piri
130+
C(c) // Mapping c
131+
```
132+
133+
- `map.getters()` and `map.actions()` expand vuex paths and adds parent instances
134+
```javascript
135+
<script>
136+
import { map } from 'vuex+';
137+
138+
export default {
139+
computed: {
140+
...map.getters({
141+
count: 'c/someGetter', // expands to 'a/b$chuu/c/someGetter'
142+
}),
143+
},
144+
}
145+
</script>
146+
---
147+
38148
### Coauthor
39149
- [Zyrica](https://github.com/zyrica)
40150

0 commit comments

Comments
 (0)