forked from verdnatura/hedera-web
82 lines
1.2 KiB
JavaScript
82 lines
1.2 KiB
JavaScript
|
|
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:
|
|
{
|
|
params:
|
|
{
|
|
type: Object
|
|
,set: function (x)
|
|
{
|
|
this.setAll (x);
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._params;
|
|
}
|
|
}
|
|
,$:
|
|
{
|
|
type: Object
|
|
,set: function (x)
|
|
{
|
|
this.setAll (x);
|
|
}
|
|
,get: function ()
|
|
{
|
|
return this._params;
|
|
}
|
|
}
|
|
}
|
|
|
|
,initialize: function (props)
|
|
{
|
|
this._params = {};
|
|
this.parent (props);
|
|
}
|
|
|
|
,keys: function ()
|
|
{
|
|
return Object.keys (this._params);
|
|
}
|
|
|
|
,assign: function (params)
|
|
{
|
|
var diff = Value.partialDiff (this._params, params);
|
|
|
|
if (diff)
|
|
{
|
|
Object.assign (this._params, diff);
|
|
this._paramsChanged (diff);
|
|
this.changed (diff);
|
|
}
|
|
}
|
|
|
|
,setAll: function (params)
|
|
{
|
|
var diff = Value.diff (this._params, params);
|
|
|
|
if (diff)
|
|
{
|
|
this._params = Value.kvClone (params);
|
|
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 () {}
|
|
});
|