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

85 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-07-03 05:49:45 +00:00
2017-05-22 07:08:21 +00:00
var Lot = require ('./lot');
2017-04-21 10:53:15 +00:00
var IteratorIface = require ('./iterator-iface');
2017-05-22 07:08:21 +00:00
var ModelIface = require ('./model-iface');
2016-09-26 09:28:47 +00:00
2017-04-21 10:53:15 +00:00
/**
2017-04-24 07:47:56 +00:00
* A light iterator for models. It assumes that its row and model properties
* are always valid.
2017-04-21 10:53:15 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports = new Class
2015-07-03 05:49:45 +00:00
({
2017-05-22 07:08:21 +00:00
Extends: Lot
2017-04-21 10:53:15 +00:00
,Implements: IteratorIface
2017-04-08 11:42:27 +00:00
,Properties:
2015-07-03 05:49:45 +00:00
{
model:
2017-04-21 10:53:15 +00:00
{
2017-05-22 07:08:21 +00:00
type: ModelIface
2017-04-21 10:53:15 +00:00
,set: function (x)
{
this._model = x;
}
,get: function ()
{
return this._model;
}
2015-07-03 05:49:45 +00:00
},
row:
2017-04-21 10:53:15 +00:00
{
2015-07-03 05:49:45 +00:00
type: Number
2017-04-21 10:53:15 +00:00
,set: function (x)
{
this._row = x;
2017-05-11 15:38:31 +00:00
this.rowChanged ();
2017-04-21 10:53:15 +00:00
}
,get: function ()
{
return this._row;
}
2015-07-03 05:49:45 +00:00
},
numRows:
{
type: Number
2017-04-21 10:53:15 +00:00
,get: function ()
{
return this._model ?
this._model.numRows : 0;
}
},
ready:
{
type: Boolean
,get: function ()
{
return this._model ?
this._model.ready : false;
}
2015-07-03 05:49:45 +00:00
}
}
2017-04-24 07:47:56 +00:00
,initialize: function (props)
{
Object.assign (this, {
_model: null
,_row: -1
2017-05-11 15:38:31 +00:00
,_rowLock: false
2017-04-24 07:47:56 +00:00
});
this.parent (props);
}
,_paramsChanged: function (diff)
{
2017-05-11 15:38:31 +00:00
if (!this._rowLock)
2017-04-24 07:47:56 +00:00
for (var key in diff)
this._model.set (this._row, key, diff[key]);
}
2017-05-11 15:38:31 +00:00
,rowChanged: function ()
2017-04-24 07:47:56 +00:00
{
2017-05-11 15:38:31 +00:00
this._rowLock = true;
2017-04-24 07:47:56 +00:00
this.params = this._model.getObject (this._row);
2017-05-11 15:38:31 +00:00
this._rowLock = false;
2017-04-24 07:47:56 +00:00
}
2015-07-03 05:49:45 +00:00
});