0
1
Fork 0
hedera-web-mindshore/js/db/iterator.js

84 lines
1.2 KiB
JavaScript

var IteratorIface = require ('./iterator-iface');
var Model = require ('./model');
/**
* A light iterator for models. It assumes that its row and model properties
* are always valid.
*/
module.exports = new Class
({
Extends: Vn.Lot
,Implements: IteratorIface
,Properties:
{
model:
{
type: Model
,set: function (x)
{
this._model = x;
}
,get: function ()
{
return this._model;
}
},
row:
{
type: Number
,set: function (x)
{
this._row = x;
this.rowChanged ();
}
,get: function ()
{
return this._row;
}
},
numRows:
{
type: Number
,get: function ()
{
return this._model ?
this._model.numRows : 0;
}
},
ready:
{
type: Boolean
,get: function ()
{
return this._model ?
this._model.ready : false;
}
}
}
,initialize: function (props)
{
Object.assign (this, {
_model: null
,_row: -1
,_rowLock: false
});
this.parent (props);
}
,_paramsChanged: function (diff)
{
if (!this._rowLock)
for (var key in diff)
this._model.set (this._row, key, diff[key]);
}
,rowChanged: function ()
{
this._rowLock = true;
this.params = this._model.getObject (this._row);
this._rowLock = false;
}
});