seamless-immutable-mergers
Advanced tools
Comparing version 2.0.1 to 2.1.0
{ | ||
"name": "seamless-immutable-mergers", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "A collection of merger functions for seamless-immutable.", | ||
"main": "seamless-immutable-mergers.js", | ||
"dependencies": { | ||
"seamless-immutable": "~2.3.2" | ||
"seamless-immutable": "~2.4.0" | ||
}, | ||
"browserDependencies": { | ||
"seamless-immutable": "~2.3.2" | ||
"seamless-immutable": "~2.4.0" | ||
}, | ||
@@ -27,3 +27,3 @@ "devDependencies": { | ||
"author": "Christian Rudh", | ||
"license": "Apache2", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -30,0 +30,0 @@ "url": "https://github.com/crudh/seamless-immutable-mergers/issues" |
@@ -5,2 +5,5 @@ seamless-immutable-mergers | ||
## Installation | ||
`npm install seamless-immutable-mergers` | ||
## The merge API | ||
@@ -71,2 +74,17 @@ If you have an immutable object that you want to merge with another object then you do the following in seamless-immutable: | ||
### equalityArrayMerger | ||
This is a merger that operates on arrays and compares the contents of the arrays. If both arrays contain the same elements (it checks each element using `===`) it will not replace the current array with the update and thus not flag that as a change. This means that if there are no other changes and the arrays contain the same elements the result of the merge will be the same object as original. Example: | ||
```javascript | ||
var data = {a: [1, 2]}; | ||
var immutableObject = immutable(data); | ||
var data2 = {a: [1, 2]}; | ||
var result = immutableObject.merge(data2, {merger: mergers.equalityArrayMerger}); | ||
result === immutableObject | ||
// true | ||
``` | ||
This can be useful for change detection, like in React's `shouldComponentUpdate`. | ||
### updatingByIdArrayMerger | ||
@@ -103,3 +121,7 @@ This is a merger that operates on arrays that contains objects with specified ids. It tries to merge each object in the target array with the object with the same id from the source array. Example: | ||
var result = immutableObject.merge(otherObject, {merger: mergers.updatingByIdArrayMerger, mergerObjectIdentifier: "id"}); | ||
var mergeConfig = { | ||
merger: mergers.updatingByIdArrayMerger, | ||
mergerObjectIdentifier: "id" | ||
}; | ||
var result = immutableObject.merge(otherObject, mergeConfig); | ||
``` | ||
@@ -131,2 +153,7 @@ | ||
## Major and minor releases | ||
### 2.1.0 | ||
Added new merger: *equalityArrayMerger*. | ||
### 2.0.0 | ||
Initial release. |
@@ -10,2 +10,13 @@ "use strict"; | ||
function equalityArrayMerger(current, other) { | ||
if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
if (current.length !== other.length) return; | ||
for (var i = 0; i < current.length; i++) { | ||
if (current[i] !== other[i]) return; | ||
} | ||
return current; | ||
} | ||
function updatingByIdArrayMerger(current, other, config) { | ||
@@ -41,3 +52,4 @@ if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
concatArrayMerger: concatArrayMerger, | ||
updatingByIdArrayMerger: updatingByIdArrayMerger | ||
updatingByIdArrayMerger: updatingByIdArrayMerger, | ||
equalityArrayMerger: equalityArrayMerger | ||
}; | ||
@@ -44,0 +56,0 @@ |
@@ -118,3 +118,2 @@ "use strict"; | ||
var result = current.merge(update, config); | ||
console.log(JSON.stringify(result)); | ||
assert.equal(result.array.length, 2); | ||
@@ -121,0 +120,0 @@ |
Sorry, the diff of this file is not supported yet
80957
22
317
156
+ Addedseamless-immutable@2.4.2(transitive)
- Removedseamless-immutable@2.3.2(transitive)
Updatedseamless-immutable@~2.4.0