immutable-object-methods
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -17,12 +17,11 @@ 'use strict'; | ||
var changesInput = function changesInput(input, keys, value) { | ||
var key = keys[0]; | ||
if (keys.length === 1) { | ||
return input[key] !== value; | ||
} | ||
for (var i = 0; i < keys.length; ++i) { | ||
if (!input) { | ||
return true; | ||
} | ||
if (!input[key]) { | ||
return true; | ||
input = input[keys[i]]; | ||
} | ||
return changesInput(input[key], keys.slice(1), value); | ||
return input !== value; | ||
}; | ||
@@ -29,0 +28,0 @@ |
import assign from 'object-assign'; | ||
const changesInput = (input, keys, value) => { | ||
const key = keys[0]; | ||
if (keys.length === 1) { | ||
return input[key] !== value; | ||
} | ||
for (let i = 0; i < keys.length; ++i) { | ||
if (!input) { | ||
return true; | ||
} | ||
if (!input[key]) { | ||
return true; | ||
input = input[keys[i]]; | ||
} | ||
return changesInput(input[key], keys.slice(1), value); | ||
return input !== value; | ||
}; | ||
@@ -15,0 +14,0 @@ |
{ | ||
"name": "immutable-object-methods", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Update normal plain javascript object, immutable style. Simlar to how immutable.js, seamless-immutable etc does it but a lot smaller and simpler.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
30
test.js
@@ -23,3 +23,3 @@ import test from 'ava'; | ||
}); | ||
const actual = setIn(input, ['a'], 'yo'); | ||
const actual = setIn(input, Object.freeze(['a']), 'yo'); | ||
const expected = { | ||
@@ -39,5 +39,31 @@ a: 'yo', | ||
}); | ||
const actual = setIn(input, ['a', 'b'], 'c'); | ||
const actual = setIn(input, Object.freeze(['a', 'b']), 'c'); | ||
const expected = input; | ||
t.is(actual, expected); | ||
}); | ||
test('setIn with nested changed value', t => { | ||
const input = Object.freeze({ | ||
a: { | ||
b: 'c' | ||
} | ||
}); | ||
const actual = setIn(input, Object.freeze(['a', 'b']), 'd'); | ||
const expected = { | ||
a: { | ||
b: 'd' | ||
} | ||
}; | ||
t.deepEqual(actual, expected); | ||
}); | ||
test('setIn with null value, unchanged', t => { | ||
const input = Object.freeze({ | ||
a: { | ||
b: 0 | ||
} | ||
}); | ||
const actual = setIn(input, Object.freeze(['a', 'b']), 0); | ||
const expected = input; | ||
t.is(actual, expected); | ||
}); |
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
6177
117