immutable-ops
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -291,4 +291,7 @@ 'use strict'; | ||
if (canMutate(obj)) return mutableSet(opts, key, obj); | ||
if (obj[key] === value) return obj; | ||
var newObj = Object.assign({}, obj); | ||
prepareNewObject(newObj); | ||
prepareNewObject(opts, newObj); | ||
newObj[key] = value; | ||
@@ -295,0 +298,0 @@ return newObj; |
@@ -260,2 +260,25 @@ 'use strict'; | ||
it('sets a value', function () { | ||
var obj = (0, _deepFreeze2['default'])({ | ||
name: 'Tommi', | ||
age: 25 | ||
}); | ||
var result = ops.set('age', 26, obj); | ||
expect(result).to.deep.equal({ | ||
name: 'Tommi', | ||
age: 26 | ||
}); | ||
}); | ||
it('sets a value and returns the initial value of no changes', function () { | ||
var obj = (0, _deepFreeze2['default'])({ | ||
name: 'Tommi', | ||
age: 25 | ||
}); | ||
var result = ops.set('age', 25, obj); | ||
expect(result).to.equal(obj); | ||
}); | ||
it('sets a value in path', function () { | ||
@@ -426,4 +449,3 @@ var obj = (0, _deepFreeze2['default'])({ | ||
var setter = ops.set(2, 3); | ||
var result = setter(arr); | ||
var result = ops.set(2, 3, arr); | ||
@@ -430,0 +452,0 @@ expect((0, _index.canMutate)(result)).to.be['false']; |
{ | ||
"name": "immutable-ops", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A collection of functions to perform immutable operations on plain JavaScript objects", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -267,4 +267,7 @@ import forOwn from 'lodash/forOwn'; | ||
if (canMutate(obj)) return mutableSet(opts, key, obj); | ||
if (obj[key] === value) return obj; | ||
const newObj = Object.assign({}, obj); | ||
prepareNewObject(newObj); | ||
prepareNewObject(opts, newObj); | ||
newObj[key] = value; | ||
@@ -271,0 +274,0 @@ return newObj; |
@@ -242,2 +242,25 @@ import chai from 'chai'; | ||
it('sets a value', () => { | ||
const obj = freeze({ | ||
name: 'Tommi', | ||
age: 25, | ||
}); | ||
const result = ops.set('age', 26, obj); | ||
expect(result).to.deep.equal({ | ||
name: 'Tommi', | ||
age: 26, | ||
}); | ||
}); | ||
it('sets a value and returns the initial value of no changes', () => { | ||
const obj = freeze({ | ||
name: 'Tommi', | ||
age: 25, | ||
}); | ||
const result = ops.set('age', 25, obj); | ||
expect(result).to.equal(obj); | ||
}); | ||
it('sets a value in path', () => { | ||
@@ -394,4 +417,3 @@ const obj = freeze({ | ||
const setter = ops.set(2, 3); | ||
const result = setter(arr); | ||
const result = ops.set(2, 3, arr); | ||
@@ -398,0 +420,0 @@ expect(canMutate(result)).to.be.false; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70926
1540