Skip to content

Commit

Permalink
_.merge =>_.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
aputinski committed Jun 13, 2016
1 parent 9ac1e74 commit 739f095
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/props/prop-set.js
Expand Up @@ -33,7 +33,7 @@ class PropSet {
this.file = file;
this.path = file.path;
this.valueTransforms = valueTransforms;
this.options = _.merge({}, defaults, options);
this.options = _.assign({}, defaults, options);

this._init();
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class PropSet {
_resolveGlobals(def) {
if (_.keys(def.global).length === 0) return;
_.forEach(def.props, (prop, key) => {
def.props[key] = _.merge({}, def.global, prop);
def.props[key] = _.assign({}, def.global, prop);
});
delete def.global;
}
Expand Down Expand Up @@ -182,8 +182,8 @@ class PropSet {

_transformValue(prop, meta) {
_.forEach(this.valueTransforms, v => {
let p = _.merge({}, prop);
let m = _.merge({}, meta);
let p = _.assign({}, prop);
let m = _.assign({}, meta);
if (v.matcher(p, m) === true) {
prop.value = v.transformer(p, m);
}
Expand Down
2 changes: 1 addition & 1 deletion test/props/mock/c.json
Expand Up @@ -26,4 +26,4 @@
"type": "color"
}
}
}
}
20 changes: 13 additions & 7 deletions test/props/prop-set.js
Expand Up @@ -177,22 +177,28 @@ describe('PropSet', function() {
});

describe('#_resolveGlobals', function() {
it ('returns undefined if no keys were found in def.global', function() {
it('returns undefined if no keys were found in def.global', function() {
var def = { global: {} };
assert(set._resolveGlobals(def) === undefined);
});
it ('merges def.global into each def.props', function() {
it('merges def.global into each def.props', function() {
var def = { global: {foo:"bar"}, props: { a: { value:"hello" } } };
set._resolveGlobals(def)
assert(_.has(def.props.a, 'foo'));
assert(def.props.a.foo === 'bar');
});
it ('doesn\'t overwrite existing keys', function() {
it('doesn\'t overwrite existing keys', function() {
var def = { global: {foo:"bar"}, props: { a: { foo:"baz" } } };
set._resolveGlobals(def)
assert(_.has(def.props.a, 'foo'));
assert(def.props.a.foo === 'baz');
});
it('doesn\'t merge object values', function() {
var def = { global: {foo:["a", "b", "c"]}, props: { a: { foo:["d"] } } };
set._resolveGlobals(def)
assert(_.has(def.props.a, 'foo'));
assert.deepEqual(def.props.a.foo, ['d']);
});
it('removes the "global" key from the def', function() {
var def = { global: {foo:"bar"}, props: { a: { foo:"baz" } } };
set._resolveGlobals(def)
Expand All @@ -201,7 +207,7 @@ describe('PropSet', function() {
});

describe('#_resolveAliases', function() {
it ('replaces all instances of an alias in string values', function() {
it('replaces all instances of an alias in string values', function() {
var def = {
aliases: { sky: "blue", land: "green" },
props: {
Expand All @@ -219,19 +225,19 @@ describe('PropSet', function() {
});

describe('#_resolveImports', function() {
it ('returns an empty array if no imports are found', function() {
it('returns an empty array if no imports are found', function() {
var def = { props: {} };
var imports = set._resolveImports(def);
assert(_.isArray(imports));
assert(imports.length === 0);
});
it ('throws an error if an import is not found', function() {
it('throws an error if an import is not found', function() {
var def = { props: {}, imports: ['./foo/bar.json'] };
assert.throws(function() {
set._resolveImports(def);
});
});
it ('returns an array of PropSets', function() {
it('returns an array of PropSets', function() {
var imports = set._resolveImports(def);
assert(_.isArray(imports));
assert(imports.length === 2);
Expand Down

0 comments on commit 739f095

Please sign in to comment.