Comparing version 0.5.2 to 0.5.3
{ | ||
"name": "can-set", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "Set logic for CanJS", | ||
@@ -5,0 +5,0 @@ "main": "src/set.js", |
@@ -296,1 +296,49 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
test("paginated and sorted is subset (#17)", function(){ | ||
var algebra = new set.Algebra( | ||
comparators.sort('sort'), | ||
comparators.rangeInclusive('start','end') | ||
); | ||
var res = algebra.subset({start: 0, end: 100, sort: "name"},{start: 0, end: 100, sort: "name"}); | ||
equal(res, true, "parent:paginate+order child:paginate+order (same set)"); | ||
res = algebra.subset({start: 0, end: 100, sort: "name"},{start: 0, end: 100, sort: "age"}); | ||
equal(res, false, "parent:paginate+order child:paginate+order (different order)"); | ||
// REMOVE FROM THE parent | ||
// parent:order | ||
res = algebra.subset({start: 0, end: 100, sort: "name"},{sort: "name"}); | ||
equal(res, true, "parent:order child:paginate+order"); | ||
res = algebra.subset({sort: "name"},{sort: "name"}); | ||
equal(res, true, "parent:order child:order (same)"); | ||
res = algebra.subset({sort: "name"},{sort: "age"}); | ||
equal(res, true, "parent:order child:order (different)"); | ||
res = algebra.subset({start: 0, end: 100},{sort: "name"}); | ||
equal(res, true, "parent:order child:paginate"); | ||
res = algebra.subset({start: 0, end: 100, sort: "age"},{sort: "name"}); | ||
equal(res, true, "parent:order child:paginate+order"); | ||
// parent:paginate | ||
res = algebra.subset({start: 0, end: 100, sort: "name"},{start: 0, end: 100}); | ||
equal(res, false, "parent:paginate child:paginate+order"); | ||
res = algebra.subset({sort: "name"},{start: 0, end: 100}); | ||
equal(res, false, "parent:paginate child:order (same)"); | ||
res = algebra.subset({start: 0, end: 100, sort: "name"},{}); | ||
equal(res, true, "parent:-- child:paginate+order"); | ||
res = algebra.subset({start: 10, end: 90, sort: "name"},{start: 0, end: 100, sort: "name"}); | ||
equal(res, true, "child in smaller range, same sort"); | ||
res = algebra.subset({start: 10, end: 90, sort: "name"},{start: 0, end: 100, sort: "age"}); | ||
equal(res, false, "child in smaller range, but different sort"); | ||
}); |
@@ -164,6 +164,19 @@ var h = require("./helpers"); | ||
// calls the operator method on different parts of the set. | ||
evaluateOperator: function(operator, a, b, aOptions, bOptions) { | ||
evaluateOperator: function(operator, a, b, aOptions, bOptions, evaluateOptions) { | ||
aOptions = aOptions || {}; | ||
bOptions = bOptions || {}; | ||
evaluateOptions = h.extend({ | ||
evaluateWhere: operator, | ||
evaluatePaginate: operator, | ||
evaluateOrder: operator, | ||
shouldEvaluatePaginate: function(aClauseProps, bClauseProps) { | ||
return aClauseProps.enabled.paginate || bClauseProps.enabled.paginate; | ||
}, | ||
shouldEvaluateOrder: function(aClauseProps, bClauseProps) { | ||
return aClauseProps.enabled.order && compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined,{},{}); | ||
} | ||
/* aClauseProps.enabled.order || bClauseProps.enabled.order */ | ||
}, evaluateOptions||{}); | ||
var aClauseProps = this.getClauseProperties(a, aOptions), | ||
@@ -174,3 +187,3 @@ bClauseProps = this.getClauseProperties(b, bOptions), | ||
var result = operator(aClauseProps.where, bClauseProps.where, | ||
var result = evaluateOptions.evaluateWhere(aClauseProps.where, bClauseProps.where, | ||
undefined, undefined, undefined, this.clauses.where, {}); | ||
@@ -181,7 +194,8 @@ | ||
// if success, and either has paginate props | ||
if(result && (aClauseProps.enabled.paginate || bClauseProps.enabled.paginate)) { | ||
if(result && evaluateOptions.shouldEvaluatePaginate(aClauseProps,bClauseProps) ) { | ||
// if they have an order, it has to be true for paginate to be valid | ||
if(aClauseProps.enabled.order || bClauseProps.enabled.order) { | ||
result = operator(aClauseProps.order, bClauseProps.order, undefined, | ||
// this isn't true if a < b, a is paginated, and b is not. | ||
if( evaluateOptions.shouldEvaluateOrder(aClauseProps,bClauseProps)) { | ||
result = evaluateOptions.evaluateOrder(aClauseProps.order, bClauseProps.order, undefined, | ||
undefined, undefined, {}, {}); | ||
@@ -193,3 +207,3 @@ | ||
if(result) { | ||
result = operator(aClauseProps.paginate, bClauseProps.paginate, | ||
result = evaluateOptions.evaluatePaginate(aClauseProps.paginate, bClauseProps.paginate, | ||
undefined, undefined, undefined, this.clauses.paginate, {}); | ||
@@ -201,3 +215,3 @@ | ||
// if orders are the same keep order! | ||
else if( result && aClauseProps.enabled.order && compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined,{},{}) ) { | ||
else if( result && evaluateOptions.shouldEvaluateOrder(aClauseProps,bClauseProps) ) { | ||
@@ -223,4 +237,4 @@ result = operator(aClauseProps.order, bClauseProps.order, undefined, | ||
// if there is a paginate and an order, order has to be the same first. | ||
if((aClauseProps.enabled.paginate || bClauseProps.enabled.paginate) && | ||
// if both have a paginate, make sure order is the same. | ||
if( bClauseProps.enabled.paginate && | ||
(aClauseProps.enabled.order || bClauseProps.enabled.order)) { | ||
@@ -227,0 +241,0 @@ // compare order clauses without any special comparators |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115525
3264