Skip to content

Commit

Permalink
Fixed some bugs in the sort-extender.
Browse files Browse the repository at this point in the history
Closes astoilkov#132.
Also fixed a bug in array-observable.move().
  • Loading branch information
Joscha Rohmann committed Feb 13, 2016
1 parent 36e9e5c commit 64f69a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/query/ExtenderHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,15 @@ 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.bind(observable.__context__));
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
2 changes: 1 addition & 1 deletion src/query/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ define([
}

for (var i = 0; i < elements.length; i++) {
element = elements[i].element;
element = elements[i].element = elements[i].element || ElementsData.byId(elements[i].elementId).dom;
chunkManager.insertAt(element, targetIndex, chunkManager.getAt(element, sourceIndex));
}

Expand Down

0 comments on commit 64f69a9

Please sign in to comment.