Skip to content

Instantly share code, notes, and snippets.

@lahmatiy
Created July 9, 2013 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahmatiy/5962364 to your computer and use it in GitHub Desktop.
Save lahmatiy/5962364 to your computer and use it in GitHub Desktop.
Path for field resolving in basis.data.value.BindValue#addLink and basis.data.value.BindValue#removeLink (resolving was dropped in 0.9.5)
basis.require('basis.data.value');
basis.require('basis.dom');
var DOM = basis.dom;
var BindValue = basis.data.value.BindValue;
var DOM_INSERT_HANDLER = function(value){
DOM.insert(DOM.clear(this), value);
};
function getFieldHandler(object){
// property
if (object instanceof BindValue)
return object.set;
// DOM
var nodeType = object.nodeType;
if (isNaN(nodeType) == false)
if (nodeType == 1)
return DOM_INSERT_HANDLER;
else
return 'nodeValue';
}
//
// BindValue#addLink
//
var addLink_ = BindValue.prototype.addLink;
BindValue.prototype.addLink = function(object, field, format){
// process field name
if (field == null)
{
// object must be an Object
// IE HtmlNode isn't instanceof Object, therefore additionaly used typeof
if (typeof object != 'object' && object instanceof Object == false)
throw this.constructor.className + '#addLink: Link to undefined object ignored';
field = getFieldHandler(object);
}
return addLink_.call(this, object, field, format);
}
//
// BindValue#removeLink
//
var removeLink_ = BindValue.prototype.removeLink;
BindValue.prototype.removeLink = function(object, field){
if (this.links_ == null) // property destroyed
return;
var deleteAll = arguments.length < 2;
// process field name
if (!deleteAll && field == null)
field = getFieldHandler(object);
return removeLink_.call(object, field);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment