2022-05-30 01:30:33 +00:00
|
|
|
|
|
|
|
var LotIface = require('./lot-iface');
|
|
|
|
var Type = require('./type');
|
|
|
|
var Value = require('./value');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A value holder, it emits the changed signal when value is changed.
|
|
|
|
* Also it can be linked with a lot value or another parameter.
|
|
|
|
*/
|
|
|
|
module.exports = new Class({
|
|
|
|
Properties: {
|
|
|
|
/**
|
|
|
|
* The parameter value.
|
|
|
|
*/
|
|
|
|
value: {
|
|
|
|
type: null
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The parameter type.
|
|
|
|
*/
|
|
|
|
type: {
|
|
|
|
type: Type
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Another parameter to bind with.
|
|
|
|
*/
|
|
|
|
param: {
|
|
|
|
type: Object
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* A lot to bind with.
|
|
|
|
*/
|
|
|
|
lot: {
|
|
|
|
type: LotIface
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The field name in the lot.
|
|
|
|
*/
|
|
|
|
name: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Determines whether the link to the lot is unidirectional, ie, a
|
|
|
|
* change in the lot updates the parameter but not viceversa.
|
|
|
|
*/
|
|
|
|
oneWay: {
|
|
|
|
type: Boolean
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_value: undefined
|
|
|
|
,_type: null
|
|
|
|
,_param: null
|
|
|
|
,_lot: null
|
2022-10-03 12:49:41 +00:00
|
|
|
,_sourceLock: false
|
2022-05-30 01:30:33 +00:00
|
|
|
,_name: null
|
|
|
|
,_oneWay: false
|
|
|
|
|
|
|
|
,_setValue: function(newValue) {
|
|
|
|
if (this._putValue(newValue))
|
|
|
|
this._notifyChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
,_putValue: function(newValue) {
|
|
|
|
if (Value.simpleEquals(newValue, this._value))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
this._value = Value.simpleClone(newValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
,_notifyChanges: function() {
|
|
|
|
this._refreshLot();
|
|
|
|
this._refreshParam();
|
|
|
|
this.emit('changed', this._value);
|
|
|
|
}
|
|
|
|
|
|
|
|
,_setType: function(type) {
|
|
|
|
this._type = type;
|
|
|
|
this._onLotChange();
|
|
|
|
}
|
2022-10-03 12:49:41 +00:00
|
|
|
|
|
|
|
,_onSourceChange(newValue) {
|
|
|
|
if (this._oneTime && this._value !== undefined)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._sourceLock = true;
|
|
|
|
this._setValue(newValue);
|
|
|
|
this._sourceLock = false;
|
|
|
|
}
|
2022-05-30 01:30:33 +00:00
|
|
|
|
|
|
|
,_setParam: function(param) {
|
2022-10-03 12:49:41 +00:00
|
|
|
this.link({_lot: null});
|
2022-05-30 01:30:33 +00:00
|
|
|
this.link({_param: param}, {changed: this._onParamChange});
|
|
|
|
this._refreshParam();
|
|
|
|
}
|
|
|
|
|
|
|
|
,_onParamChange: function() {
|
2022-10-03 12:49:41 +00:00
|
|
|
if (this._sourceLock || !this._param) return;
|
|
|
|
this._onSourceChange(this._param.value);
|
2022-05-30 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,_refreshParam: function() {
|
2022-10-03 12:49:41 +00:00
|
|
|
if (this._sourceLock || !this._param || this._oneWay)
|
2022-05-30 01:30:33 +00:00
|
|
|
return;
|
|
|
|
|
2022-10-03 12:49:41 +00:00
|
|
|
this._sourceLock = true;
|
2022-05-30 01:30:33 +00:00
|
|
|
this._param.value = this._value;
|
2022-10-03 12:49:41 +00:00
|
|
|
this._sourceLock = false;
|
2022-05-30 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,_setLot: function(lot) {
|
2022-10-03 12:49:41 +00:00
|
|
|
this.link({_param: null});
|
2022-05-30 01:30:33 +00:00
|
|
|
this.link({_lot: lot}, {change: this._onLotChange});
|
|
|
|
this._onLotChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
,_onLotChange: function() {
|
2022-10-03 12:49:41 +00:00
|
|
|
if (this._sourceLock || !this._lot || !this._name)
|
2022-05-30 01:30:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
var newValue = this._lot.get(this._name, this._type);
|
2022-10-03 12:49:41 +00:00
|
|
|
this._onSourceChange(newValue);
|
2022-05-30 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,_refreshLot: function() {
|
2022-10-03 12:49:41 +00:00
|
|
|
if (this._sourceLock || !this._name || !this._lot || this._oneWay)
|
2022-05-30 01:30:33 +00:00
|
|
|
return;
|
|
|
|
|
2022-10-03 12:49:41 +00:00
|
|
|
this._sourceLock = true;
|
2022-05-30 01:30:33 +00:00
|
|
|
this._lot.set(this._name, this._value);
|
2022-10-03 12:49:41 +00:00
|
|
|
this._sourceLock = false;
|
2022-05-30 01:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,_setName: function(name) {
|
|
|
|
this._name = name;
|
|
|
|
this._onLotChange();
|
|
|
|
}
|
|
|
|
});
|