seamless-immutable-mergers
Advanced tools
Comparing version 7.0.0 to 7.1.0
{ | ||
"name": "seamless-immutable-mergers", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "A collection of merger functions for seamless-immutable.", | ||
@@ -5,0 +5,0 @@ "main": "seamless-immutable-mergers.js", |
{ | ||
"name": "seamless-immutable-mergers", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"description": "A collection of merger functions for seamless-immutable.", | ||
@@ -11,3 +11,3 @@ "main": "seamless-immutable-mergers.js", | ||
"chai": "~3.5.0", | ||
"mocha": "~2.4.5" | ||
"mocha": "~3.2.0" | ||
}, | ||
@@ -14,0 +14,0 @@ "scripts": { |
@@ -187,5 +187,16 @@ seamless-immutable-mergers | ||
This merger will check both arrays and only do anything if both of them has an object with the specified identifier at position 0. It will then assume that the rest of the arrays only contains such objects. | ||
It can also be used with the `deep` configuration to do this recursively. | ||
It can also be used with the following options: | ||
##### `deep?: boolean` | ||
Default is `false`. Control whether the merger should or not to do this recursively. | ||
##### `modifier?: 'push' | 'unshift'` | ||
Default is `push`. Manages the way the new data is added to the array (first or last position - respectivaly). | ||
## Releases | ||
### 7.1.0 | ||
*updatingByIdArrayMerger* received a config option for how new items are added to the array (thanks to @daviscabral) | ||
### 7.0.0 | ||
@@ -192,0 +203,0 @@ Updated to *[seamless-immutable](https://github.com/rtfeldman/seamless-immutable)* 7.0.0 and bumped the major version to be in sync. |
@@ -53,3 +53,6 @@ "use strict"; | ||
if (matchingCurrentIndex === undefined) { | ||
resultList.push(other[j]); | ||
var modifier = config.modifier; | ||
if (modifier !== 'push' && modifier !== 'unshift') | ||
modifier = 'push'; | ||
resultList[modifier](other[j]); | ||
} else { | ||
@@ -56,0 +59,0 @@ resultList[matchingCurrentIndex] = resultList[matchingCurrentIndex].merge(other[j], config); |
@@ -248,2 +248,92 @@ "use strict"; | ||
}); | ||
it("adds new items to the end when no modifier is provided", function() { | ||
var current = immutable({ | ||
array: [ | ||
{ | ||
id: '6a230f52-a757-11e8-8ed2-3c15c2de1bfa', | ||
name: 'Categories' | ||
}, | ||
{ | ||
id: '73c3d1a4-a757-11e8-9634-3c15c2de1bfa', | ||
name: 'Tags' | ||
} | ||
] | ||
}); | ||
var update = { | ||
array: [ | ||
{ | ||
id: 'a9e79932-a757-11e8-b3e7-3c15c2de1bfa', | ||
name: 'Posts' | ||
} | ||
] | ||
}; | ||
var result = current.merge(update, config); | ||
assert.equal(result.array[0].id, '6a230f52-a757-11e8-8ed2-3c15c2de1bfa'); | ||
assert.equal(result.array[1].id, '73c3d1a4-a757-11e8-9634-3c15c2de1bfa'); | ||
assert.equal(result.array[2].id, 'a9e79932-a757-11e8-b3e7-3c15c2de1bfa'); | ||
}); | ||
it("adds new items to the beginning when unshift modifier is provided", function() { | ||
var current = immutable({ | ||
array: [ | ||
{ | ||
id: '6a230f52-a757-11e8-8ed2-3c15c2de1bfa', | ||
name: 'Categories' | ||
}, | ||
{ | ||
id: '73c3d1a4-a757-11e8-9634-3c15c2de1bfa', | ||
name: 'Tags' | ||
} | ||
] | ||
}); | ||
var update = { | ||
array: [ | ||
{ | ||
id: 'a9e79932-a757-11e8-b3e7-3c15c2de1bfa', | ||
name: 'Posts' | ||
} | ||
] | ||
}; | ||
var result = current.merge(update, Object.assign({ modifier: 'unshift' }, config)); | ||
assert.equal(result.array[0].id, 'a9e79932-a757-11e8-b3e7-3c15c2de1bfa'); | ||
assert.equal(result.array[1].id, '6a230f52-a757-11e8-8ed2-3c15c2de1bfa'); | ||
assert.equal(result.array[2].id, '73c3d1a4-a757-11e8-9634-3c15c2de1bfa'); | ||
}); | ||
it("adds new items to the end when an invalid modifier is provided", function() { | ||
var current = immutable({ | ||
array: [ | ||
{ | ||
id: '6a230f52-a757-11e8-8ed2-3c15c2de1bfa', | ||
name: 'Categories' | ||
}, | ||
{ | ||
id: '73c3d1a4-a757-11e8-9634-3c15c2de1bfa', | ||
name: 'Tags' | ||
} | ||
] | ||
}); | ||
var update = { | ||
array: [ | ||
{ | ||
id: 'a9e79932-a757-11e8-b3e7-3c15c2de1bfa', | ||
name: 'Posts' | ||
} | ||
] | ||
}; | ||
var result = current.merge(update, Object.assign({ modifier: 'invalid' }, config)); | ||
assert.equal(result.array[0].id, '6a230f52-a757-11e8-8ed2-3c15c2de1bfa'); | ||
assert.equal(result.array[1].id, '73c3d1a4-a757-11e8-9634-3c15c2de1bfa'); | ||
assert.equal(result.array[2].id, 'a9e79932-a757-11e8-b3e7-3c15c2de1bfa'); | ||
}); | ||
}); |
37179
584
230
10