realm-js/lib/results.js

34 lines
711 B
JavaScript
Raw Normal View History

2015-10-08 00:08:19 +00:00
'use strict';
let rpc = require('./rpc');
let util = require('./util');
let idKey = util.idKey;
let realmKey = util.realmKey;
let resizeListKey = util.resizeListKey;
2015-10-08 00:08:19 +00:00
exports.create = create;
function create(realmId, info) {
let results = util.createList(null, getterForLength, getterForIndex);
2015-10-08 00:08:19 +00:00
let size = info.size;
results[realmKey] = realmId;
results[idKey] = info.id;
2015-10-08 00:08:19 +00:00
results[resizeListKey](size);
2015-10-08 00:08:19 +00:00
return results;
}
function getterForLength() {
return rpc.getResultsSize(this[realmKey], this[idKey]);
}
function getterForIndex(index) {
return function() {
let realmId = this[realmKey];
return rpc.getResultsItem(realmId, this[idKey], index);
};
}