hedera-web/web/js/vn/hash-param.js

88 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-08-17 18:02:14 +00:00
Vn.HashParam = new Class
({
Extends: Vn.Object
,Tag: 'vn-hash-param'
2015-10-14 11:51:43 +00:00
,Child: 'param'
2015-08-17 18:02:14 +00:00
,Properties:
{
param:
{
type: Vn.Param
,set: function (x)
{
this.link ({_param: x}, {'changed': this._onParamChange});
this._refreshParam ();
}
,get: function ()
{
return this._param;
}
},
key:
{
type: String
,set: function (x)
{
this._key = x;
this._onHashChange ();
}
,get: function ()
{
return this._key;
}
}
}
,lock: false
,value: undefined
,_key: null
,initialize: function (props)
{
this.parent (props);
var listener = Vn.Hash.getListener ();
this.link ({_listener: listener}, {'changed': this._onHashChange});
this._onHashChange ();
}
,_onHashChange: function ()
{
if (!this._key || !this._listener)
return;
var newValue = Vn.Hash.get (this._key);
if (this.value != newValue)
{
this.value = newValue;
this.signalEmit ('changed');
this._refreshParam ();
}
}
,_refreshParam: function ()
{
if (this._param && !this.lock)
{
this.lock = true;
this._param.value = this.value;
this.lock = false;
}
}
,_onParamChange: function ()
{
if (this.lock)
return;
var map = {};
map[this.key] = this._param.value;
this.lock = true;
Vn.Hash.add (map);
this.lock = false;
}
});