hedera-web/js/vn/iterator.js

76 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2022-05-30 01:30:33 +00:00
var Lot = require('./lot');
var IteratorIface = require('./iterator-iface');
var ModelIface = require('./model-iface');
/**
* A light iterator for models. It assumes that its row and model properties
* are always valid.
*/
module.exports = new Class({
Extends: Lot
,Implements: IteratorIface
,Properties: {
model: {
type: ModelIface
2022-11-16 01:46:44 +00:00
,set(x) {
2022-05-30 01:30:33 +00:00
this._model = x;
}
2022-11-16 01:46:44 +00:00
,get() {
2022-05-30 01:30:33 +00:00
return this._model;
}
},
row: {
type: Number
2022-11-16 01:46:44 +00:00
,set(x) {
2022-05-30 01:30:33 +00:00
this._row = x;
this.rowChanged();
}
2022-11-16 01:46:44 +00:00
,get() {
2022-05-30 01:30:33 +00:00
return this._row;
}
},
numRows: {
type: Number
2022-11-16 01:46:44 +00:00
,get() {
2022-05-30 01:30:33 +00:00
return this._model ?
this._model.numRows : 0;
}
},
ready: {
type: Boolean
2022-11-16 01:46:44 +00:00
,get() {
2022-05-30 01:30:33 +00:00
return this._model ?
this._model.ready : false;
}
}
}
,_model: null
2022-11-16 01:46:44 +00:00
,initialize(props) {
2022-05-30 01:30:33 +00:00
Object.assign(this, {
_row: -1
,_rowLock: false
});
2022-06-06 16:02:17 +00:00
Lot.prototype.initialize.call(this, props);
2022-05-30 01:30:33 +00:00
}
2022-11-16 01:46:44 +00:00
,_paramsChanged(diff) {
2022-05-30 01:30:33 +00:00
if (!this._rowLock)
for (var key in diff)
this._model.set(this._row, key, diff[key]);
}
2022-11-16 01:46:44 +00:00
,rowChanged() {
2022-05-30 01:30:33 +00:00
var row;
if (this._model)
row = this._model.getObject(this._row);
this._rowLock = true;
this.params = row != null ? row : {};
this._rowLock = false;
}
});