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

70 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-05-30 01:30:33 +00:00
var VnObject = require('./object');
var LotIface = require('./lot-iface');
var Value = require('./value');
module.exports = new Class({
Extends: VnObject
,Implements: LotIface
,Tag: 'vn-lot'
,Properties: {
2022-06-06 12:49:18 +00:00
$: {
2022-05-30 01:30:33 +00:00
type: Object
,set: function(x) {
this.setAll(x);
}
,get: function() {
return this._params;
}
}
2022-06-06 12:49:18 +00:00
,params: {
2022-05-30 01:30:33 +00:00
type: Object
,set: function(x) {
2022-06-06 12:49:18 +00:00
this.$ = x;
2022-05-30 01:30:33 +00:00
}
,get: function() {
2022-06-06 12:49:18 +00:00
return this.$;
2022-05-30 01:30:33 +00:00
}
}
}
,initialize: function(props) {
2022-06-18 21:04:34 +00:00
this._params = new Proxy({}, {
set(obj, prop, value) {
return Reflect.set(obj, prop, value);
}
});
2022-06-06 16:02:17 +00:00
VnObject.prototype.initialize.call(this, props);
2022-05-30 01:30:33 +00:00
}
,keys: function() {
return Object.keys(this._params);
}
,assign: function(params) {
var diff = Value.partialDiff(this._params, params);
this._assign(diff);
}
,setAll: function(params) {
var diff = Value.diff(this._params, params);
this._assign(diff);
}
,_assign: function(diff) {
if (diff) {
Object.assign(this._params, diff);
this._paramsChanged(diff);
this.changed(diff);
}
}
/**
* Called when lot params changes, can be implemented by child classes to be
* notified about changes.
*
* @param {Object} diff Changed parameters and its new values
*/
,_paramsChanged: function() {}
});