make .parented() work so #each can use it

The problem was we don't currently chain callbacks like rendered and parented when a class and superclass have different implementations.  The plumbing here is all rather arbitrary, considering our inheritance model is not finalized (and we may even do away with it, a la React) and "parented" is at best an undocumented but usable peer to "rendered".

Renamed the "parented" signal from DomRange to Component "notifyParented".
This commit is contained in:
David Greenspan
2013-12-11 19:11:21 -08:00
parent 218caaf004
commit b9bb01e537
3 changed files with 22 additions and 9 deletions

View File

@@ -298,7 +298,7 @@ _extend(UI.Component, {
// XXX we don't really want this to be a user-visible callback,
// it's just a particular signal we need from DomRange.
UI.Component.parented = function () {
UI.Component.notifyParented = function () {
var self = this;
for (var comp = self; comp; comp = comp._super) {
var events = (comp.hasOwnProperty('_events') && comp._events) || null;
@@ -336,10 +336,26 @@ UI.Component.parented = function () {
});
}
// XXX think about this callback's timing
var updatedTemplateInstance = false;
// XXX this is an undocumented callback
if (self.parented) {
Deps.nonreactive(function () {
if (! updatedTemplateInstance) {
updateTemplateInstance(self);
updatedTemplateInstance = true;
}
self.parented.call(self.templateInstance);
});
}
// XXX fix this callback's timing
if (self.rendered) {
Deps.nonreactive(function () {
updateTemplateInstance(self);
if (! updatedTemplateInstance) {
updateTemplateInstance(self);
updatedTemplateInstance = true;
}
self.rendered.call(self.templateInstance);
});
}

View File

@@ -114,10 +114,8 @@ var rangeParented = function (range) {
});
}
// XXX is this a real callback? what about chaining? etc.
if (range.component.parented) {
range.component.parented();
}
if (range.component.notifyParented)
range.component.notifyParented();
// recurse on member ranges
var members = range.members;

View File

@@ -6,8 +6,7 @@ UI.Each = Component.extend({
this.sequence = this.data;
this.data = undefined;
},
// xcxc -> parented
rendered: function () {
parented: function () {
var self = this.__component__;
var range = self.dom;