Skip to content

Commit

Permalink
Changing instancemarker from # to $
Browse files Browse the repository at this point in the history
  • Loading branch information
presidenten committed Apr 25, 2017
1 parent 1446110 commit ff10830
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
37 changes: 19 additions & 18 deletions dist/vuex+.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clone from 'clone';

var getStoreInstanceName = function (storeName, instance) {
if (instance) {
return storeName + '#' + instance;
return storeName + '$' + instance;
}
return storeName;
};
Expand All @@ -28,8 +28,8 @@ function addModuleToNames(name, subapi, instanceName) {
var path = subapi[type][pathName];
var subname = path.match(/[a-zA-Z]*/)[0];
result[type][pathName] = name + '/' + path;
if(instanceName) {
result[type][pathName] = result[type][pathName].replace(subname, subname + '#' + instanceName);
if (instanceName) {
result[type][pathName] = result[type][pathName].replace(subname, subname + '$' + instanceName);
}
});
} else {
Expand Down Expand Up @@ -78,7 +78,7 @@ var storeWrapper = function (store) {
// Clone modules
if (store.modules) {
Object.keys(store.modules).forEach(function (name) {
var hashPos = name.indexOf('#');
var hashPos = name.indexOf('$');
var instanceName = hashPos >= 0 ? name.slice(hashPos + 1) : undefined;

store.api[name] = addModuleToNames(camelCasedName, store.modules[name].api, instanceName);
Expand Down Expand Up @@ -251,7 +251,7 @@ var generateAPI = function (newImporter) {

var addStore = add;

function searchDeeper(map, key, log) {
function searchDeeper(map, key) {
var submodules = Object.keys(map).filter(function (k) { return k !== 'get' && k !== 'act' && k !== 'mutate'; });
var keyIsInMap = submodules.indexOf(key) >= 0;

Expand All @@ -271,15 +271,16 @@ function searchDeeper(map, key, log) {
return result;
}

function getFullPath(config) {
var suffix = config.subinstance ? '#' + config.subinstance : '';
function getFullPath(config) {
var suffix = config.subinstance ? '$' + config.subinstance : '';
var getterKey = config.mappedKey.match(/[a-zA-Z]*/)[0];

var localApi = api$1[config.vuexPlus.baseStoreName];
if (getterKey !== config.vuexPlus.baseStoreName) {
localApi = searchDeeper(api$1[config.vuexPlus.baseStoreName], getterKey + suffix);
}
return localApi[config.method][config.key].replace(config.vuexPlus.baseStoreName, config.vuexPlus.storeInstanceName);
return localApi[config.method][config.key]
.replace(config.vuexPlus.baseStoreName, config.vuexPlus.storeInstanceName);
}

var map = {
Expand All @@ -288,11 +289,11 @@ var map = {
Object.keys(m).forEach(function (key) {
result[key] = function get() {
var path = getFullPath({
method: 'get',
key: key,
mappedKey: m[key],
subinstance: this.subinstance,
vuexPlus: this['$vuex+']
method: 'get',
key: key,
mappedKey: m[key],
subinstance: this.subinstance,
vuexPlus: this['$vuex+'],
});

// localApi.get[key].replace(this['$vuex+'].baseStoreName, this['$vuex+'].storeInstanceName)
Expand All @@ -307,11 +308,11 @@ var map = {
Object.keys(m).forEach(function (key) {
result[key] = function dispatch(payload) {
var path = getFullPath({
method: 'act',
key: key,
mappedKey: m[key],
subinstance: this.subinstance,
vuexPlus: this['$vuex+']
method: 'act',
key: key,
mappedKey: m[key],
subinstance: this.subinstance,
vuexPlus: this['$vuex+'],
});
return this.$store.dispatch(path, payload);
};
Expand Down
2 changes: 1 addition & 1 deletion src/instanceHandling/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const getStoreInstanceName = (storeName, instance) => {
if (instance) {
return storeName + '#' + instance;
return storeName + '$' + instance;
}
return storeName;
};
Expand Down
4 changes: 2 additions & 2 deletions src/instanceHandling/storeWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function addModuleToNames(name, subapi, instanceName) {
const subname = path.match(/[a-zA-Z]*/)[0];
result[type][pathName] = name + '/' + path;
if (instanceName) {
result[type][pathName] = result[type][pathName].replace(subname, subname + '#' + instanceName);
result[type][pathName] = result[type][pathName].replace(subname, subname + '$' + instanceName);
}
});
} else {
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function (store) {
// Clone modules
if (store.modules) {
Object.keys(store.modules).forEach((name) => {
const hashPos = name.indexOf('#');
const hashPos = name.indexOf('$');
const instanceName = hashPos >= 0 ? name.slice(hashPos + 1) : undefined;

store.api[name] = addModuleToNames(camelCasedName, store.modules[name].api, instanceName);
Expand Down
2 changes: 1 addition & 1 deletion src/vuex+.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function searchDeeper(map, key) {
}

function getFullPath(config) {
const suffix = config.subinstance ? '#' + config.subinstance : '';
const suffix = config.subinstance ? '$' + config.subinstance : '';
const getterKey = config.mappedKey.match(/[a-zA-Z]*/)[0];

let localApi = apiManager.api[config.vuexPlus.baseStoreName];
Expand Down

0 comments on commit ff10830

Please sign in to comment.