2016-12-23 08:57:49 +00:00
|
|
|
|
2017-04-19 06:16:37 +00:00
|
|
|
var VnObject = require ('./object');
|
2017-04-10 16:23:40 +00:00
|
|
|
var LotIface = require ('./lot-iface');
|
2017-04-24 07:47:56 +00:00
|
|
|
var Value = require ('./value');
|
2017-04-10 16:23:40 +00:00
|
|
|
|
2016-12-23 08:57:49 +00:00
|
|
|
module.exports = new Class
|
|
|
|
({
|
2017-04-19 06:16:37 +00:00
|
|
|
Extends: VnObject
|
2017-04-10 16:23:40 +00:00
|
|
|
,Implements: LotIface
|
|
|
|
,Tag: 'vn-lot'
|
|
|
|
,Properties:
|
2017-03-30 11:44:53 +00:00
|
|
|
{
|
|
|
|
params:
|
|
|
|
{
|
|
|
|
type: Object
|
2017-04-10 16:23:40 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
2017-05-11 15:38:31 +00:00
|
|
|
this.setAll (x);
|
2017-04-24 07:47:56 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._params;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
,$:
|
|
|
|
{
|
|
|
|
type: Object
|
|
|
|
,set: function (x)
|
|
|
|
{
|
2017-05-11 15:38:31 +00:00
|
|
|
this.setAll (x);
|
2017-04-10 16:23:40 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._params;
|
|
|
|
}
|
2017-03-30 11:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 16:23:40 +00:00
|
|
|
,initialize: function (props)
|
|
|
|
{
|
|
|
|
this._params = {};
|
|
|
|
this.parent (props);
|
|
|
|
}
|
|
|
|
|
|
|
|
,keys: function ()
|
2016-12-23 08:57:49 +00:00
|
|
|
{
|
2017-04-10 16:23:40 +00:00
|
|
|
return Object.keys (this._params);
|
2016-12-23 08:57:49 +00:00
|
|
|
}
|
2017-03-30 11:44:53 +00:00
|
|
|
|
2017-04-24 07:47:56 +00:00
|
|
|
,assign: function (params)
|
2017-03-30 11:44:53 +00:00
|
|
|
{
|
2017-04-24 07:47:56 +00:00
|
|
|
var diff = Value.partialDiff (this._params, params);
|
2017-03-30 11:44:53 +00:00
|
|
|
|
2017-04-24 07:47:56 +00:00
|
|
|
if (diff)
|
|
|
|
{
|
|
|
|
Object.assign (this._params, diff);
|
|
|
|
this._paramsChanged (diff);
|
|
|
|
this.changed (diff);
|
|
|
|
}
|
2017-04-08 11:42:27 +00:00
|
|
|
}
|
2017-04-24 07:47:56 +00:00
|
|
|
|
|
|
|
,setAll: function (params)
|
|
|
|
{
|
|
|
|
var diff = Value.diff (this._params, params);
|
2017-05-11 15:38:31 +00:00
|
|
|
|
2017-04-24 07:47:56 +00:00
|
|
|
if (diff)
|
|
|
|
{
|
|
|
|
this._params = Value.kvClone (params);
|
|
|
|
this._paramsChanged (diff);
|
|
|
|
this.changed (diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-05 09:50:42 +00:00
|
|
|
* Called when lot params changes, can be implemented by child classes to be
|
|
|
|
* notified about changes.
|
2017-04-24 07:47:56 +00:00
|
|
|
*
|
|
|
|
* @param {Object} diff Changed parameters and its new values
|
|
|
|
*/
|
|
|
|
,_paramsChanged: function () {}
|
2016-12-23 08:57:49 +00:00
|
|
|
});
|