-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from crudh/umd
Start using UMD pattern
- Loading branch information
Showing
4 changed files
with
84 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "seamless-immutable-mergers", | ||
"version": "2.2.0", | ||
"description": "A collection of merger functions for seamless-immutable.", | ||
"main": "seamless-immutable-mergers.js", | ||
"dependencies": { | ||
"seamless-immutable": "~2.4.2" | ||
}, | ||
"moduleType": [ | ||
"amd", | ||
"globals", | ||
"node" | ||
], | ||
"keywords": [ | ||
"immutable", | ||
"merger" | ||
], | ||
"authors": [ | ||
"Christian Rudh <[email protected]>" | ||
], | ||
"license": "Apache-2.0", | ||
"homepage": "https://github.com/crudh/seamless-immutable-mergers", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"name": "seamless-immutable-mergers", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A collection of merger functions for seamless-immutable.", | ||
"main": "seamless-immutable-mergers.js", | ||
"dependencies": { | ||
"seamless-immutable": "~2.4.1" | ||
"seamless-immutable": "~2.4.2" | ||
}, | ||
"browserDependencies": { | ||
"seamless-immutable": "~2.4.1" | ||
"seamless-immutable": "~2.4.2" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.9.2", | ||
|
@@ -23,7 +23,7 @@ | |
"keywords": [ | ||
"immutable merger" | ||
], | ||
"author": "Christian Rudh", | ||
"author": "Christian Rudh <[email protected]>", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/crudh/seamless-immutable-mergers/issues" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,65 @@ | ||
"use strict"; | ||
var immutable = require("seamless-immutable"); | ||
(function (root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define(['seamless-immutable'], factory); | ||
} else if (typeof module === 'object' && module.exports) { | ||
module.exports = factory(require('seamless-immutable')); | ||
} else { | ||
root.returnExports = factory(root.b); | ||
} | ||
}(this, function (immutable) { | ||
function concatArrayMerger(current, other) { | ||
if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
|
||
function concatArrayMerger(current, other) { | ||
if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
return current.concat(other); | ||
} | ||
|
||
return current.concat(other); | ||
} | ||
function equalityArrayMerger(current, other) { | ||
if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
if (current.length !== other.length) return; | ||
|
||
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; | ||
} | ||
|
||
for (var i = 0; i < current.length; i++) { | ||
if (current[i] !== other[i]) return; | ||
return current; | ||
} | ||
|
||
return current; | ||
} | ||
|
||
function updatingByIdArrayMerger(current, other, config) { | ||
if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
if (current.length === 0 || other.length === 0) return; | ||
function updatingByIdArrayMerger(current, other, config) { | ||
if (!(current instanceof Array) || !(other instanceof Array)) return; | ||
if (current.length === 0 || other.length === 0) return; | ||
|
||
var identifier = config.mergerObjectIdentifier; | ||
if (current[0] === null || !(typeof current[0] === "object") || !current[0][identifier]) return; | ||
if (other[0] === null || !(typeof other[0] === "object") || !other[0][identifier]) return; | ||
var identifier = config.mergerObjectIdentifier; | ||
if (current[0] === null || !(typeof current[0] === "object") || !current[0][identifier]) return; | ||
if (other[0] === null || !(typeof other[0] === "object") || !other[0][identifier]) return; | ||
|
||
var currentMap = {}; | ||
for (var i = 0; i < current.length; i++) { | ||
currentMap[current[i][identifier]] = i; | ||
} | ||
var currentMap = {}; | ||
for (var i = 0; i < current.length; i++) { | ||
currentMap[current[i][identifier]] = i; | ||
} | ||
|
||
var resultList = current.asMutable(); | ||
for (var j = 0; j < other.length; j++) { | ||
var matchingCurrentIndex = currentMap[other[j][identifier]]; | ||
var resultList = current.asMutable(); | ||
for (var j = 0; j < other.length; j++) { | ||
var matchingCurrentIndex = currentMap[other[j][identifier]]; | ||
|
||
if (matchingCurrentIndex === undefined) { | ||
resultList.push(other[j]); | ||
} else { | ||
resultList[matchingCurrentIndex] = resultList[matchingCurrentIndex].merge(other[j], config); | ||
if (matchingCurrentIndex === undefined) { | ||
resultList.push(other[j]); | ||
} else { | ||
resultList[matchingCurrentIndex] = resultList[matchingCurrentIndex].merge(other[j], config); | ||
} | ||
} | ||
} | ||
|
||
return immutable(resultList); | ||
} | ||
return immutable(resultList); | ||
} | ||
|
||
// Export the library | ||
var immutableMergers = { | ||
concatArrayMerger: concatArrayMerger, | ||
updatingByIdArrayMerger: updatingByIdArrayMerger, | ||
equalityArrayMerger: equalityArrayMerger | ||
}; | ||
// Export the library | ||
var immutableMergers = { | ||
concatArrayMerger: concatArrayMerger, | ||
updatingByIdArrayMerger: updatingByIdArrayMerger, | ||
equalityArrayMerger: equalityArrayMerger | ||
}; | ||
|
||
Object.freeze(immutableMergers); | ||
Object.freeze(immutableMergers); | ||
|
||
module.exports = immutableMergers; | ||
return immutableMergers; | ||
})); |