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+ */
17export 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+ */
919export 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+ */
1732export 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+ */
2443export 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+ */
3761export 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+ */
6290export const getSubInstances = ( path ) => {
6391 if ( path ) {
6492 const subInstances = path . match ( / \$ \w * / g) ;
0 commit comments