Skip to content

Commit

Permalink
Merge pull request #8 from crudh/umd
Browse files Browse the repository at this point in the history
Start using UMD pattern
  • Loading branch information
crudh committed Aug 5, 2015
2 parents cd359ac + 9ce8d48 commit 20093a5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.idea
*.iml
29 changes: 29 additions & 0 deletions bower.json
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"
]
}
8 changes: 4 additions & 4 deletions package.json
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",
Expand All @@ -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"
Expand Down
90 changes: 49 additions & 41 deletions seamless-immutable-mergers.js
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;
}));

0 comments on commit 20093a5

Please sign in to comment.