realm-js/lib/results.js

34 lines
728 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 = Symbol();
let realmKey = Symbol();
let prototype = util.createListPrototype(getterForLength, getterForIndex);
exports.create = create;
function create(realmId, info) {
let results = Object.create(prototype);
let size = info.size;
results[realmKey] = realmId;
results[idKey] = info.resultsId;
results[util.growListPrototypeKey](size);
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);
};
}