webclient/js/Table.js

43 lines
714 B
JavaScript

import of from UnitJS.Fun;
import {compare, of, proj} from UnitJS.Fun;
function Table(sortCriterion) {
var items = {};
return {
get: get,
getAll: getAll,
insert: insert,
insertAll: insertAll,
remove: remove
};
function get(key) {
return items[key];
}
function getAll(criterion) {
return Object.keys(items)
.map(function(key) {return {key: key, value: items[key]};})
.filter(criterion || function() {return true;})
.sort(compare(sortCriterion));
}
function insert(key, value) {
items[key] = value;
}
function insertAll(newItems) {
for(var key in newItems) {
insert(key, newItems[key]);
}
}
function remove(key) {
delete items[key];
}
}
return {
make: Table
}