Skip to content

Commit d532f3a

Browse files
committed
Updated comments
1 parent 80febd8 commit d532f3a

File tree

11 files changed

+96
-17
lines changed

11 files changed

+96
-17
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ Vuex+ is an opinionated library that handles instances in Vuex and makes it easy
77
```
88
![piri](./docs/instances.gif)
99

10-
### Heads up!!
11-
Still prerelease, but the library should reach 1.0.0 and get a proper release by mid may. Very close now.
12-
1310
### Enhancements over Vuex instance handling (2.3.0)+
1411
From Vuex 2.3.0 onward vuex supports the same notation as vue `data` property to [handle instantiation](https://vuex.vuejs.org/en/modules.html).
1512

@@ -33,9 +30,6 @@ Check out the extensive tutorial bundled with the example:
3330
- Vuex module filename
3431
- Vuex module variable names
3532

36-
### Todo
37-
- Clean up comments
38-
3933
### Coauthor
4034
- [Zyrica](https://github.com/zyrica)
4135

src/api/api.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { getTagName, getInstances } from '../common/helpers.js';
44
* The api for all stores
55
* The api is autogenerated once the module importer has been set
66
* ```
7-
* api.aStore.get.something => vuex magic string for vuex getter
7+
* api.someStore.get.something => vuex magic string for vuex getter
88
* ```
99
*/
1010
export const api = {};
11+
/**
12+
* Set api
13+
* @param {Object} newApi The new api
14+
*/
1115
export const setApi = (newApi) => {
1216
Object.keys(newApi).forEach((key) => {
1317
api[key] = newApi[key];
@@ -17,6 +21,12 @@ export const setApi = (newApi) => {
1721
/**
1822
* Match array of results strings and return the ones matching parent instances
1923
*/
24+
/**
25+
* Match array of results strings and return the ones matching parent instances
26+
* @param {array} allResults All unmatched results
27+
* @param {array} pathInstances All the instances found in the instance branch
28+
* @return {array} An array with results matched the the instance branch
29+
*/
2030
export const matchToInstances = (allResults, pathInstances) => {
2131
const results = [];
2232
allResults
@@ -45,9 +55,9 @@ export const matchToInstances = (allResults, pathInstances) => {
4555

4656
/**
4757
* Input subpath and figure out full path
48-
* @param (string) subpath
49-
* @param (Object) self - vuex module `this`
50-
* @returns (string) full path
58+
* @param {string} subpath The subpath to start from
59+
* @param {Object} self Vue component `.this`
60+
* @return {string} Full path
5161
*/
5262
export const getFullPath = (subpath, self) => {
5363
if (!subpath) {
@@ -95,6 +105,10 @@ export const getFullPath = (subpath, self) => {
95105

96106
/**
97107
* Set instance to all toplevel stores in `storeApi` paths
108+
* @param {Object} storeApi The store api
109+
* @param {string} baseStoreName Base store name
110+
* @param {string} newStoreName New store name
111+
* @return {Object} Store api remapped with toplevel instance names
98112
*/
99113
export function remapBaseStore(storeApi, baseStoreName, newStoreName) {
100114
newStoreName = newStoreName || baseStoreName;

src/api/global.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { getLocalPath } from '../common/helpers.js';
44
import vuexInstance from '../vuexInstance.js';
55

66
export default {
7+
/**
8+
* Get the whole global api
9+
* @return {Object} Global api
10+
*/
711
get api() {
812
return clone(api);
913
},

src/api/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default {
2121

2222
/**
2323
* Map local paths `require('./example-substore.js').api.act.value`
24-
* to the corresponding vuex getter.
24+
* to the corresponding vuex action.
2525
* @param {Object} map - Object of all method properties to be mapped to actions
2626
* @returns {Object} - Object containing the mapped actions
2727
*/

src/common/helpers.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1+
/**
2+
* Get store instance name
3+
* @param {string} storeName Store name
4+
* @param {string} instance Instance name
5+
* @return {string} Store instance name
6+
*/
17
export const getStoreInstanceName = (storeName, instance) => {
28
if (instance) {
39
return storeName + '$' + instance;
410
}
511
return storeName;
612
};
713

8-
14+
/**
15+
* Convert kebab and snake case to camelCase
16+
* @param {string} str The string to Convert
17+
* @return {string} Camel cased string
18+
*/
919
export const toCamelCase = (str) => {
1020
if (!str || typeof str !== 'string') {
1121
return '';
1222
}
1323
return str.replace(/(-|_)([\w])/g, s => s[1].toUpperCase());
1424
};
1525

16-
26+
/**
27+
* Return the local path of the instance branch
28+
* @param {string} path The global path
29+
* @param {Object} state The vuex context state
30+
* @return {string} The local path with all instances
31+
*/
1732
export const getLocalPath = (path, state) => {
1833
const storeName = state['vuex+'].storeName;
1934
const instance = state['vuex+'].instance;
2035
return path.replace(storeName, getStoreInstanceName(storeName, instance));
2136
};
2237

23-
38+
/**
39+
* Support method that gets tag name for error logs
40+
* @param {Object} self Vue component `.this`
41+
* @return {string} <tag-name>
42+
*/
2443
export const getTagName = (self) => {
2544
let tag = 'unknown-tag';
2645
if (self.$parent) {
@@ -33,7 +52,12 @@ export const getTagName = (self) => {
3352
return '<' + tag + '>';
3453
};
3554

36-
55+
/**
56+
* Returns all instances in the current instance branch as an ordered array
57+
* @param {string} subpath The subpath to explore
58+
* @param {Object} self Vue component `.this`
59+
* @return {array} The instances as array
60+
*/
3761
export const getInstances = (subpath, self) => {
3862
let path = self.instance ? '/$' + self.instance : '';
3963
let parent = self;
@@ -58,7 +82,11 @@ export const getInstances = (subpath, self) => {
5882
return instances;
5983
};
6084

61-
85+
/**
86+
* Returns subInstances from local path
87+
* @param {string} path Path to explore
88+
* @return {array} Subinstances as ordered array
89+
*/
6290
export const getSubInstances = (path) => {
6391
if (path) {
6492
const subInstances = path.match(/\$\w*/g);

src/common/hmrHandler.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ import vuexInstance from '../vuexInstance.js';
44

55
let handlers = [];
66

7+
/**
8+
* Returns all current vuex module handlers
9+
* @return {array} All current vuex module handlers
10+
*/
711
export const getHandlers = () => handlers.slice();
12+
/**
13+
* Clears the current vuex module handlers
14+
*/
815
export const clearHandlers = () => {
916
handlers = [];
1017
};
1118

19+
/**
20+
* Registers module for HMR
21+
* @param {Object} newStore The store object
22+
* @param {string} baseStoreName Base store name
23+
* @param {string} storeInstanceName Store instance name
24+
*/
1225
export const registerForHMR = (newStore, baseStoreName, storeInstanceName) => {
1326
handlers.push({
1427
storeName: baseStoreName + '-store',
@@ -17,10 +30,18 @@ export const registerForHMR = (newStore, baseStoreName, storeInstanceName) => {
1730
});
1831
};
1932

33+
/**
34+
* Unregisters for HMR
35+
* @param {Object} newStore The store object
36+
*/
2037
export const unregisterForHMR = (newStore) => {
2138
handlers = handlers.filter(h => h.newStore !== newStore);
2239
};
2340

41+
/**
42+
* The hmr handler
43+
* @param {array} updatedModules All the updated modules returned from HMR plugin
44+
*/
2445
export const hmrHandler = (updatedModules) => {
2546
const modules = {};
2647
Object.keys(updatedModules).forEach((key) => {

src/mixins/addStore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { registerForHMR, unregisterForHMR } from '../common/hmrHandler.js';
55

66
let importer;
77

8+
/**
9+
* Setup module with new importer from webpack-context-vuex-hmr
10+
* @param {Object} newImporter The importer
11+
*/
812
export function setup(newImporter) {
913
importer = newImporter;
1014
}

src/mixins/install.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export default {
2+
/**
3+
* Use to install as Vue plugin
4+
* @param {Object} Vue The vue instance
5+
*/
26
install(Vue) {
37
Vue.mixin({
48
props: ['instance'],

src/mixins/setupVuexPlus.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { setup } from './addStore.js';
33
import { hmrHandler } from '../common/hmrHandler.js';
44
import vuexInstance from '../vuexInstance.js';
55

6+
/**
7+
* Setup vuex plus with the base vuex store
8+
* @param {Object} $store Base vuex store
9+
*/
610
export default function setupVuexPlus($store) {
711
vuexInstance.store = $store;
812
const importer = contextHmr.getNewInstance();

src/store/newInstance.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import clone from 'clone';
22
import { remapBaseStore } from '../api/api.js';
33

4+
/**
5+
* Make new instance with remapped api.
6+
* @param {Object} substore The substore to remap and clone
7+
* @param {string} instance Instance name
8+
* @return {Object} Remapped store
9+
*/
410
export default (substore, instance) => {
511
const result = clone(substore);
612
result.api = remapBaseStore(result.api, result.name, result.name + '$' + instance);

0 commit comments

Comments
 (0)