-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christopher Baker
committed
Feb 16, 2018
1 parent
ee88f94
commit bd40cbd
Showing
9 changed files
with
11,846 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*can-set@1.5.1#src/clause*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-util/js/assign', | ||
'can-util/js/each' | ||
], function (require, exports, module) { | ||
var assign = require('can-util/js/assign'); | ||
var each = require('can-util/js/each'); | ||
var clause = {}; | ||
module.exports = clause; | ||
clause.TYPES = [ | ||
'where', | ||
'order', | ||
'paginate', | ||
'id' | ||
]; | ||
each(clause.TYPES, function (type) { | ||
var className = type.charAt(0).toUpperCase() + type.substr(1); | ||
clause[className] = function (compare) { | ||
assign(this, compare); | ||
}; | ||
clause[className].type = type; | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,42 @@ | ||
/*can-set@1.5.1#src/get*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'./compare', | ||
'./helpers', | ||
'can-util/js/each' | ||
], function (require, exports, module) { | ||
var compare = require('./compare'); | ||
var h = require('./helpers'); | ||
var each = require('can-util/js/each'); | ||
var filterData = function (data, clause, props) { | ||
return h.filter.call(data, function (item) { | ||
var isSubset = compare.subset(item, clause, undefined, undefined, undefined, props, {}); | ||
return isSubset; | ||
}); | ||
}; | ||
module.exports = { | ||
subsetData: function (a, b, bData, algebra) { | ||
var aClauseProps = algebra.getClauseProperties(a); | ||
var bClauseProps = algebra.getClauseProperties(b); | ||
var options = {}; | ||
var aData = filterData(bData, aClauseProps.where, algebra.clauses.where); | ||
if (aData.length && (aClauseProps.enabled.order || bClauseProps.enabled.order)) { | ||
options = {}; | ||
var propName = h.firstProp(aClauseProps.order), compareOrder = algebra.clauses.order[propName]; | ||
aData = aData.sort(function (aItem, bItem) { | ||
return compareOrder(a[propName], aItem, bItem); | ||
}); | ||
} | ||
if (aData.length && (aClauseProps.enabled.paginate || bClauseProps.enabled.paginate)) { | ||
options = {}; | ||
compare.subset(aClauseProps.paginate, bClauseProps.paginate, undefined, undefined, undefined, algebra.clauses.paginate, options); | ||
each(options.getSubsets, function (filter) { | ||
aData = filter(a, b, aData, algebra, options); | ||
}); | ||
} | ||
return aData; | ||
} | ||
}; | ||
}); |
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,179 @@ | ||
/*can-set@1.5.1#src/helpers*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-util/js/assign', | ||
'can-util/js/each', | ||
'can-util/js/last' | ||
], function (require, exports, module) { | ||
var assign = require('can-util/js/assign'); | ||
var each = require('can-util/js/each'); | ||
var last = require('can-util/js/last'); | ||
var IgnoreType = function () { | ||
}; | ||
var helpers; | ||
module.exports = helpers = { | ||
eachInUnique: function (a, acb, b, bcb, defaultReturn) { | ||
var bCopy = assign({}, b), res; | ||
for (var prop in a) { | ||
res = acb(a[prop], b[prop], a, b, prop); | ||
if (res !== undefined) { | ||
return res; | ||
} | ||
delete bCopy[prop]; | ||
} | ||
for (prop in bCopy) { | ||
res = bcb(undefined, b[prop], a, b, prop); | ||
if (res !== undefined) { | ||
return res; | ||
} | ||
} | ||
return defaultReturn; | ||
}, | ||
doubleLoop: function (arr, callbacks) { | ||
if (typeof callbacks === 'function') { | ||
callbacks = { iterate: callbacks }; | ||
} | ||
var i = 0; | ||
while (i < arr.length) { | ||
if (callbacks.start) { | ||
callbacks.start(arr[i]); | ||
} | ||
var j = i + 1; | ||
while (j < arr.length) { | ||
if (callbacks.iterate(arr[j], j, arr[i], i) === false) { | ||
arr.splice(j, 1); | ||
} else { | ||
j++; | ||
} | ||
} | ||
if (callbacks.end) { | ||
callbacks.end(arr[i]); | ||
} | ||
i++; | ||
} | ||
}, | ||
identityMap: function (arr) { | ||
var map = {}; | ||
each(arr, function (value) { | ||
map[value] = 1; | ||
}); | ||
return map; | ||
}, | ||
arrayUnionIntersectionDifference: function (arr1, arr2) { | ||
var map = {}; | ||
var intersection = []; | ||
var union = []; | ||
var difference = arr1.slice(0); | ||
each(arr1, function (value) { | ||
map[value] = true; | ||
union.push(value); | ||
}); | ||
each(arr2, function (value) { | ||
if (map[value]) { | ||
intersection.push(value); | ||
var index = helpers.indexOf.call(difference, value); | ||
if (index !== -1) { | ||
difference.splice(index, 1); | ||
} | ||
} else { | ||
union.push(value); | ||
} | ||
}); | ||
return { | ||
intersection: intersection, | ||
union: union, | ||
difference: difference | ||
}; | ||
}, | ||
arraySame: function (arr1, arr2) { | ||
if (arr1.length !== arr2.length) { | ||
return false; | ||
} | ||
var map = helpers.identityMap(arr1); | ||
for (var i = 0; i < arr2.length; i++) { | ||
var val = map[arr2[i]]; | ||
if (!val) { | ||
return false; | ||
} else if (val > 1) { | ||
return false; | ||
} else { | ||
map[arr2[i]]++; | ||
} | ||
} | ||
return true; | ||
}, | ||
indexOf: Array.prototype.indexOf || function (item) { | ||
for (var i = 0, thisLen = this.length; i < thisLen; i++) { | ||
if (this[i] === item) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
}, | ||
map: Array.prototype.map || function (cb) { | ||
var out = []; | ||
for (var i = 0, len = this.length; i < len; i++) { | ||
out.push(cb(this[i], i, this)); | ||
} | ||
return out; | ||
}, | ||
filter: Array.prototype.filter || function (cb) { | ||
var out = []; | ||
for (var i = 0, len = this.length; i < len; i++) { | ||
if (cb(this[i], i, this)) { | ||
out.push(this[i]); | ||
} | ||
} | ||
return out; | ||
}, | ||
ignoreType: new IgnoreType(), | ||
firstProp: function (set) { | ||
for (var prop in set) { | ||
return prop; | ||
} | ||
}, | ||
index: function (compare, items, props) { | ||
if (!items || !items.length) { | ||
return undefined; | ||
} | ||
if (compare(props, items[0]) === -1) { | ||
return 0; | ||
} else if (compare(props, last(items)) === 1) { | ||
return items.length; | ||
} | ||
var low = 0, high = items.length; | ||
while (low < high) { | ||
var mid = low + high >>> 1, item = items[mid], computed = compare(props, item); | ||
if (computed === -1) { | ||
high = mid; | ||
} else { | ||
low = mid + 1; | ||
} | ||
} | ||
return high; | ||
}, | ||
defaultSort: function (sortPropValue, item1, item2) { | ||
var parts = sortPropValue.split(' '); | ||
var sortProp = parts[0]; | ||
var item1Value = item1[sortProp]; | ||
var item2Value = item2[sortProp]; | ||
var temp; | ||
var desc = parts[1] || ''; | ||
desc = desc.toLowerCase() === 'desc'; | ||
if (desc) { | ||
temp = item1Value; | ||
item1Value = item2Value; | ||
item2Value = temp; | ||
} | ||
if (item1Value < item2Value) { | ||
return -1; | ||
} | ||
if (item1Value > item2Value) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
}; | ||
}); |
Oops, something went wrong.