fixed parent issue (only one parent per Y.Xml type)

This commit is contained in:
DadaMonad 2015-02-25 23:41:57 +00:00
parent 9059618d1f
commit 82f11c421f
11 changed files with 114 additions and 52 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,13 @@ module.exports = function() {
};
Operation.prototype.callEvent = function() {
return this.forwardEvent.apply(this, [this].concat(__slice.call(arguments)));
var callon;
if (this.custom_type != null) {
callon = this.getCustomType();
} else {
callon = this;
}
return this.forwardEvent.apply(this, [callon].concat(__slice.call(arguments)));
};
Operation.prototype.forwardEvent = function() {

View File

@ -46,13 +46,31 @@ YXml = (function() {
this._model.val("parent", this._xml.parent);
}
}
delete this._xml;
this._setModel(this._model);
return this._model;
};
YXml.prototype._setModel = function(_at__model) {
this._model = _at__model;
return delete this._xml;
delete this._xml;
return this._model.observe(function(events) {
var c, event, i, parent, _i, _j, _len, _len1, _ref;
for (_i = 0, _len = events.length; _i < _len; _i++) {
event = events[_i];
if (event.name === "parent" && event.type !== "add") {
parent = event.oldValue;
_ref = parent.getChildren();
for (i = _j = 0, _len1 = _ref.length; _j < _len1; i = ++_j) {
c = _ref[i];
if (c === this) {
parent._model.val("children")["delete"](i);
break;
}
}
}
}
return void 0;
});
};
YXml.prototype._setParent = function(parent) {
@ -220,19 +238,9 @@ YXml = (function() {
};
YXml.prototype.remove = function() {
var c, i, parent, _i, _len, _ref;
parent = this._model.val("parent");
if (parent instanceof YXml) {
_ref = parent.getChildren();
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
c = _ref[i];
if (c === this) {
parent._model.val("children")["delete"](i);
break;
}
}
}
return void 0;
var parent;
parent = this._model["delete"]("parent");
return this;
};
YXml.prototype.removeAttr = function(attrName) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -70,7 +70,11 @@ module.exports = ()->
# TODO: Do something with timeouts. You don't want this to fire for every operation (e.g. insert).
# TODO: do you need callEvent+forwardEvent? Only one suffices probably
callEvent: ()->
@forwardEvent @, arguments...
if @custom_type?
callon = @getCustomType()
else
callon = @
@forwardEvent callon, arguments...
#
# Fire an event and specify in which context the listener is called (set 'this').

View File

@ -32,11 +32,21 @@ class YXml
@_model.val("children", new Y.List())
if @_xml.parent?
@_model.val("parent", @_xml.parent)
delete @_xml
@_setModel @_model
@_model
_setModel: (@_model)->
delete @_xml
@_model.observe (events)->
for event in events
if event.name is "parent" and event.type isnt "add"
parent = event.oldValue
for c,i in parent.getChildren()
if c is @
parent._model.val("children").delete i
break
undefined
_setParent: (parent)->
if parent instanceof YXml
@ -188,13 +198,8 @@ class YXml
# .remove()
#
remove: ()->
parent = @_model.val("parent")
if parent instanceof YXml
for c,i in parent.getChildren()
if c is @
parent._model.val("children").delete i
break
undefined
parent = @_model.delete("parent")
@
#
# Remove an attribute from this element

File diff suppressed because one or more lines are too long

2
y.js

File diff suppressed because one or more lines are too long