Skip to content

Commit

Permalink
Merge pull request #133 from Kanaye/fix-#132
Browse files Browse the repository at this point in the history
Fixed issues with the sort-extender described in #132.
  • Loading branch information
astoilkov committed Feb 14, 2016
2 parents 4c4ccbc + 19a4bd3 commit 8e602c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/query/DomQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ define([
elementData.observables[observable.__id__ + method.query] = observable;
observable._elements.push({
elementId: elementData.id,
element: elementData.dom || elementData.virtual._el,
cache: [method],
context: context
});
Expand Down
16 changes: 13 additions & 3 deletions src/query/ExtenderHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,18 @@ define([
} else if (operation.type == 'sort') {
if (blocks.isString(operation.sort)) {
collection = blocks.clone(collection).sort(function (valueA, valueB) {
return valueA[operation.sort] - valueB[operation.sort];
valueA = blocks.unwrap(valueA[operation.sort]);
valueB = blocks.unwrap(valueB[operation.sort]);
if (valueA > valueB) {
return 1;
}
if (valueA < valueB) {
return -1;
}
return 0;
});
} else if (blocks.isFunction(operation.sort)) {
collection = blocks.clone(collection).sort(operation.sort);
collection = blocks.clone(collection).sort(operation.sort.bind(observable.__context__));
} else {
collection = blocks.clone(collection).sort();
}
Expand Down Expand Up @@ -204,11 +212,13 @@ define([
break;
case EXISTS:
newConnections[index] = viewIndex;
if (view.__value__.indexOf(collection[index]) != index) {
view.move(view.__value__.indexOf(collection[index]), index);
}
viewIndex++;
break;
}
});

view._connections = newConnections;
view.update = update;
view.update();
Expand Down

0 comments on commit 8e602c3

Please sign in to comment.