can-query-logic
Advanced tools
Comparing version 1.1.12 to 1.1.13
{ | ||
"name": "can-query-logic", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"description": "query data", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
@@ -88,1 +88,16 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
QUnit.test("Missed schema on helper.getIndex #45", function() { | ||
var items = [ | ||
{id: 1, name: "Item 0"}, | ||
{id: 2, name: "Item 1"}, | ||
{id: 3, name: "Item 2"}, | ||
{id: 4, name: "Item 3"}, | ||
{id: 5, name: "Item 4"} | ||
]; | ||
var compare = helpers.sorter("name", {}); | ||
var schema = { keys: {}, identity: ["id"] }; | ||
QUnit.equal(helpers.getIndex(compare,items, {id: 2, name: "Item 1"}, schema), 1); | ||
}); |
@@ -58,8 +58,8 @@ var canReflect = require("can-reflect"); | ||
// see getIdentityIndexByDirection | ||
getIdentityIndex: function(compare, items, props, startIndex) { | ||
var identity = canReflect.getIdentity(props), | ||
getIdentityIndex: function(compare, items, props, startIndex, schema) { | ||
var identity = canReflect.getIdentity(props, schema), | ||
starterItem = items[startIndex]; | ||
// check if the middle has a match | ||
if (compare(props, starterItem) === 0) { | ||
if (identity === canReflect.getIdentity(starterItem)) { | ||
if (identity === canReflect.getIdentity(starterItem, schema)) { | ||
return startIndex; | ||
@@ -69,3 +69,3 @@ } | ||
var rightResult = this.getIdentityIndexByDirection(compare, items, props, startIndex+1, 1), | ||
var rightResult = this.getIdentityIndexByDirection(compare, items, props, startIndex+1, 1, schema), | ||
leftResult; | ||
@@ -75,3 +75,3 @@ if(rightResult.index) { | ||
} else { | ||
leftResult = this.getIdentityIndexByDirection(compare, items, props, startIndex-1, -1); | ||
leftResult = this.getIdentityIndexByDirection(compare, items, props, startIndex-1, -1, schema); | ||
} | ||
@@ -88,5 +88,5 @@ if(leftResult.index !== undefined) { | ||
// -1 for left | ||
getIdentityIndexByDirection: function(compare, items, props, startIndex, direction) { | ||
getIdentityIndexByDirection: function(compare, items, props, startIndex, direction, schema) { | ||
var currentIndex = startIndex; | ||
var identity = canReflect.getIdentity(props); | ||
var identity = canReflect.getIdentity(props, schema); | ||
while(currentIndex >= 0 && currentIndex < items.length) { | ||
@@ -96,3 +96,3 @@ var currentItem = items[currentIndex]; | ||
if(computed === 0) { | ||
if( identity === canReflect.getIdentity(currentItem)) { | ||
if( identity === canReflect.getIdentity(currentItem, schema)) { | ||
return {index: currentIndex}; | ||
@@ -108,3 +108,3 @@ } | ||
// | ||
getIndex: function(compare, items, props) { | ||
getIndex: function(compare, items, props, schema) { | ||
if (!items || !items.length) { | ||
@@ -130,3 +130,3 @@ return undefined; | ||
if (computed === 0) { | ||
return this.getIdentityIndex(compare, items, props, mid); | ||
return this.getIdentityIndex(compare, items, props, mid, schema); | ||
} else if (computed === -1) { | ||
@@ -133,0 +133,0 @@ high = mid; |
@@ -284,3 +284,3 @@ var canSymbol = require("can-symbol"); | ||
// Makes a sort type that can make a compare function using the SetType | ||
var Sort = BasicQuery.makeSort(keys, hydrateAndValue); | ||
var Sort = BasicQuery.makeSort(schema, hydrateAndValue); | ||
var serializer = new Serializer(serializeMap); | ||
@@ -287,0 +287,0 @@ serializer.add(comparisonsConverter.serializer); |
@@ -359,1 +359,12 @@ var BasicQuery = require("./basic-query"); | ||
}); | ||
QUnit.test(".index should work with literal objects", function() { | ||
var query = new BasicQuery({ | ||
sort: "name" | ||
}); | ||
var items = [{id: 1, name: "Item 0"}, {id: 2, name: "Item 1"}]; | ||
var res = query.index({id: 1, name: "Item 1"}, items); | ||
QUnit.equal(res, 1, "Item index at 1"); | ||
}); |
@@ -40,3 +40,4 @@ var set = require("../set"); | ||
// WILL MAKE A TYPE FOR SORTING | ||
function makeSort(schemaKeys, hydrateAndValue) { | ||
function makeSort(schema, hydrateAndValue) { | ||
var schemaKeys = schema.keys; | ||
// Makes gt and lt functions that `helpers.sorter` can use | ||
@@ -111,2 +112,3 @@ // to make a `compare` function for `Array.sort(compare)`.` | ||
this.key = key; | ||
this.schema = schema; | ||
this.compare = helpers.sorter(key, sorters); | ||
@@ -134,3 +136,3 @@ } | ||
var DefaultSort = makeSort({}); | ||
var DefaultSort = makeSort({ keys: {}, identity: ["id"] }); | ||
@@ -240,3 +242,3 @@ | ||
// use the passed sort's compare function | ||
return helpers.getIndex(this.sort.compare, items, props); | ||
return helpers.getIndex(this.sort.compare, items, props, this.sort.schema); | ||
}, | ||
@@ -243,0 +245,0 @@ isMember: function(props) { |
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
396232
11056