Comparing version 0.6.0 to 0.6.1
@@ -1380,2 +1380,28 @@ 'use strict'; | ||
const numberSortAsc = (branch, path) => (key1, key2) => { | ||
const leaf1 = branch.leaves[getByPath(branch, key1, path)]; | ||
const leaf2 = branch.leaves[getByPath(branch, key2, path)]; | ||
return (leaf1 && compute(branch, leaf1)) - (leaf2 && compute(branch, leaf2)) | ||
}; | ||
const numberSortDesc = (branch, path) => (key1, key2) => { | ||
const leaf1 = branch.leaves[getByPath(branch, key1, path)]; | ||
const leaf2 = branch.leaves[getByPath(branch, key2, path)]; | ||
return (leaf2 && compute(branch, leaf2)) - (leaf1 && compute(branch, leaf1)) | ||
}; | ||
const stringSortAsc = (branch, path) => (key1, key2) => { | ||
const leaf1 = branch.leaves[getByPath(branch, key1, path)]; | ||
const leaf2 = branch.leaves[getByPath(branch, key2, path)]; | ||
return String(leaf1 && compute(branch, leaf1)) | ||
.localeCompare(String(leaf2 && compute(branch, leaf2))) | ||
}; | ||
const stringSortDesc = (branch, path) => (key1, key2) => { | ||
const leaf1 = branch.leaves[getByPath(branch, key1, path)]; | ||
const leaf2 = branch.leaves[getByPath(branch, key2, path)]; | ||
return String(leaf2 && compute(branch, leaf2)) | ||
.localeCompare(String(leaf1 && compute(branch, leaf1))) | ||
}; | ||
const cache = (socket, isMaster, id, stamp) => { | ||
@@ -1522,14 +1548,6 @@ if (!socket.cache) socket.cache = { master: {}, branch: {}, strings: {} }; | ||
if (sort && sort.path) { | ||
originalKeys = [...originalKeys].sort((key1, key2) => { | ||
const leaf1 = branch.leaves[getByPath(branch, key1, sort.path)]; | ||
const leaf2 = branch.leaves[getByPath(branch, key2, sort.path)]; | ||
if (sort.type === 'N') { | ||
const result = (leaf1 && compute(branch, leaf1)) - (leaf2 && compute(branch, leaf2)); | ||
return sort.desc ? result * -1 : result | ||
} else if (sort.type === 'S') { | ||
const result = String(leaf1 && compute(branch, leaf1)) | ||
.localeCompare(String(leaf2 && compute(branch, leaf2))); | ||
return sort.desc ? result * -1 : result | ||
} | ||
}); | ||
const sortFunction = sort.type === 'N' | ||
? sort.desc ? numberSortDesc : numberSortAsc | ||
: sort.desc ? stringSortDesc : stringSortAsc; | ||
originalKeys = [...originalKeys].sort(sortFunction(branch, sort.path)); | ||
} | ||
@@ -1536,0 +1554,0 @@ |
{ | ||
"name": "stx", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "a blazing fast state manager with network sync out of the box", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
463455
6180