Skip to content

Commit

Permalink
fixup! fixup! fixup! Use bem decl for merge, subtract and intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
skad0 committed Sep 23, 2016
1 parent c69003b commit e8f96c0
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions lib/deps/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,48 +239,47 @@ module.exports = {
/**
* Coverts declaration mod and val to modName and modVal
*
* @param {Array} deps
* @param {Array|Object} deps
* @return {Array}
*/
_convertFromMod: function (deps) {
Array.isArray(deps) || (deps = [deps]);

return deps.map(function (item) {
if (item.mod) {
var tmp = {};

tmp.block = item.block;
item.elem && (tmp.elem = item.elem);
tmp.modName = item.mod;
item.val && (tmp.modVal = item.val);

return tmp;
}
return item;
});
return _switchModsFormat('mod', {
mod: 'modName',
val: 'modVal'
}, deps);
},

/**
* Coverts declaration modName and modVal to mod and val
*
* @param {Array} deps
* @param {Array|Object} deps
* @return {Array}
*/
_convertToMod: function (deps) {
Array.isArray(deps) || (deps = [deps]);
return _switchModsFormat('modName', {
modName: 'mod',
modVal: 'val'
}, deps);
}
};

return deps.map(function (item) {
if (item.modName) {
var tmp = {};
/**
* Switch declaration mod format
*
* @param {String} conditionKey mod or modName
* @param {Object} modsMap map of replacements (for example mod: 'modName')
* @param {Array|Object} deps
* @return {Array}
*/
function _switchModsFormat (conditionKey, modsMap, deps) {
Array.isArray(deps) || (deps = [deps]);

tmp.block = item.block;
item.elem && (tmp.elem = item.elem);
tmp.mod = item.modName;
item.modVal && (tmp.val = item.modVal);
return deps.map(function (item) {
if (!item[conditionKey]) return item;

return tmp;
}
return item;
});
}
};
return Object.keys(item).reduce(function (acc, key) {
acc[modsMap[key] || key] = item[key];
return acc;
}, {});
});
}

0 comments on commit e8f96c0

Please sign in to comment.