remove old comments

This commit is contained in:
David Greenspan
2013-05-21 14:27:15 -07:00
parent 497ce9f71f
commit a0468350ee
2 changed files with 1 additions and 336 deletions

View File

@@ -470,292 +470,6 @@ _.extend(Component.prototype, {
rebuilt: function () {}
});
//////////////////////////////////////////////////
/*
Component = function (args) {
this.parent = null;
this.nameInParent = '';
this.children = {};
this.isInited = false;
this.isBuilt = false;
this.isAttached = false;
this.isDestroyed = false;
this.dom = null; // Chunk, if built
this._fragment = null; // DocumentFragment, if built; empty when attached
this._uniqueIdCounter = 1;
this._args = args;
this._argDeps = {};
};
_.extend(Component.prototype, {
_requireAlive: function () {
if (this.isDestroyed)
throw new Error("Component was destroyed");
},
_forceInit: function () {
this._requireAlive();
if (! this.isInited) {
this.init();
this.isInited = true;
}
},
_build: function () {
this._forceInit();
if (this.isBuilt)
throw new Error("Component already built");
this._fragment = document.createDocumentFragment();
this.build(this._fragment);
if (! this.dom)
throw new Error("build() must call setBounds()");
this.isBuilt = true;
this.built();
},
attach: function (parent, before) {
this._forceInit();
if (this.isAttached)
throw new Error("Component already attached");
if (! this.isBuilt)
this._build();
parent.insertBefore(this._fragment, before);
this.isAttached = true;
this.attached();
return this;
},
detach: function () {
this._requireAlive();
if (! this.isAttached)
throw new Error("Component not attached");
var start = this.dom.firstNode();
var end = this.dom.lastNode();
var frag = this._fragment;
// extract start..end into frag
var parent = start.parentNode;
var before = start.previousSibling;
var after = end.nextSibling;
var n;
while ((n = (before ? before.nextSibling : parent.firstChild)) &&
(n !== after))
frag.appendChild(n);
this.isAttached = false;
this.detached();
return this;
},
destroy: function () {
if (! this.isDestroyed) {
this.isDestroyed = true;
// maybe GC the DOM sooner
this.dom = null;
this._fragment = null;
this.destroyed();
var children = this.children;
for (var k in children)
if (children.hasOwnProperty(k))
children[k].destroy();
if (this.parent && ! this.parent.isDestroyed)
delete this.parent.children[this.nameInParent];
this.children = {};
}
return this;
},
hasChild: function (name) {
return this.children.hasOwnProperty(name);
},
addChild: function (name, childComponent) {
if (name instanceof Component) {
// omitted name arg
childComponent = name;
name = null;
}
// omitted name, generate unique child ID
if (name === null || typeof name === 'undefined')
name = "__child#" + (this._uniqueIdCounter++) + "__";
name = String(name);
if (! (childComponent instanceof Component))
throw new Error("not a Component: " + childComponent);
this._requireAlive();
if (this.hasChild(name))
throw new Error("Already have a child named: " + name);
if (childComponent.isDestroyed)
throw new Error("Can't add a destroyed component");
if (childComponent.isInited)
throw new Error("Can't add a previously added or built component");
this.children[name] = childComponent;
childComponent._added(name, this);
},
setChild: function (name, childClass, childArgs) {
name = String(name);
this._requireAlive();
if (this.hasChild(name)) {
var oldChild = this.children[name];
if (oldChild.constructor === childClass) {
// old child present with same class
oldChild.update(childArgs);
} else {
var newChild = new childClass(childArgs);
if (oldChild.isAttached) {
var beforeNode = oldChild.lastNode().nextSibling;
var parentNode = oldChild.parentNode();
this.removeChild(name);
this.addChild(name, newChild);
newChild.attach(parentNode, beforeNode);
} else {
this.addChild(newChild);
}
}
} else {
this.addChild(name, new childClass(childArgs));
}
},
_added: function (name, parent) {
name = String(name);
this.nameInParent = name;
this.parent = parent;
this._forceInit();
},
removeChild: function (name) {
name = String(name);
this._requireAlive();
if (! this.hasChild(name))
throw new Error("No such child component: " + name);
var childComponent = this.children[name];
if (childComponent.isDestroyed) {
// shouldn't be possible, because destroying a component
// deletes it from the parent's children dictionary,
// but just in case...
delete this.children[name];
} else {
if (childComponent.isAttached)
childComponent.detach();
childComponent.destroy();
}
},
setBounds: function (start, end) {
end = end || start;
if (start instanceof Component)
start = start.dom;
if (end instanceof Component)
end = end.dom;
if (! (start instanceof Chunk || (start && start.nodeType)))
throw new Error("setBounds: start must be a built Component or a Node");
if (! (end instanceof Chunk || (end && end.nodeType)))
throw new Error("setBounds: end must be a built Component or a Node");
if (! this.dom) {
this.dom = new Chunk(start, end);
} else {
this.dom.set(start, end);
}
},
setStart: function (start) {
if (start instanceof Component)
start = start.dom;
if (! (start instanceof Chunk || (start && start.nodeType)))
throw new Error("setStart: start must be a built Component or a Node");
if (! this.dom)
throw new Error("Can only call setStart after setBounds has been called");
this.dom.start = start;
},
setEnd: function (end) {
if (end instanceof Component)
end = end.dom;
if (! (end instanceof Chunk || (end && end.nodeType)))
throw new Error("setEnd: end must be a built Component or a Node");
if (! this.dom)
throw new Error("Can only call setEnd after setBounds has been called");
this.dom.end = end;
},
getArg: function (argName) {
var dep = (this._argDeps.hasOwnProperty(argName) ?
this._argDeps[argName] :
(this._argDeps[argName] = new Deps.Dependency));
dep.depend();
return this._args[argName];
},
update: function (args) {
var oldArgs = this._args;
this._args = args;
var argDeps = this._argDeps;
for (var k in args) {
if (args.hasOwnProperty(k) &&
argDeps.hasOwnProperty(k) &&
! EJSON.equal(args[k], oldArgs[k])) {
argDeps[k].invalidate();
delete oldArgs[k];
}
}
for (var k in oldArgs) {
if (oldArgs.hasOwnProperty(k) &&
argDeps.hasOwnProperty(k)) {
argDeps[k].invalidate();
}
}
this.updated(args, oldArgs);
},
findOne: function (selector) { return this.dom.findOne(selector); },
findAll: function (selector) { return this.dom.findAll(selector); },
firstNode: function () { return this.dom.firstNode(); },
lastNode: function () { return this.dom.lastNode(); },
parentNode: function () { return this.dom.parentNode(); },
// Above methods are NOT overridable.
//
// These are all overridable, with the behavior that all implementations
// are executed from super to sub.
init: function () {},
build: function (frag) {},
built: function () {},
attached: function () {},
detached: function () {},
destroyed: function () {},
updated: function (args, oldArgs) {},
// This is overridable but should probably get normal override behavior;
// it has a return value and we only run one implementation.
toHtml: function () {
return '';
}
});
*/
////////////////////
// Require ComponentClass.create(...) instead of
// new CompomentClass(...) because a factory method gives
@@ -854,9 +568,3 @@ RootComponent = Component.extend({
buf.component(bodyClass.create());
}
});
// need **rebuild**; "render" runs in a reactive context
// What does RenderBuffer do to build a subcomponent?
// Assigning Chunks; build and rebuild

View File

@@ -1,11 +1,7 @@
// TODO
//
// Make the function argument to component
// run reactively.
//
// Then make openTag attributes
// reactive too.
// Make openTag attributes reactive.
RenderBuffer = function (component) {
this._component = component;
@@ -186,42 +182,3 @@ _.extend(RenderBuffer.prototype, {
};
}
});
// CHANGES TO COMPONENT NEEDED:
//
// - childKey, elementKey -- call things "key"
// - no attach/detach -- need to wire things up from HTML...
// openChunk, closeChunk
//
// Drop comemnts at start and finish. Comments may have
// to be fished out due to missing close tags (some fun
// logic there). Eventually, can produce cleaner HTML
// using attributes in some cases instead of comments.
// Chunks bound components, and also text/raw inclusions.
// Consecutive openChunks or closeChunks create Chunks
// defined in terms of each other.
//
// When building is finished, it produces HTML and some
// other data. We don't do materialization, because in
// the server-side rendering case, the browser does that!
//
// After materialization, we want to somehow:
// - recalculate all the helpers with deps tracking
// - assign elements to components
// - set bounds of components
//
// ... based on walking the DOM.
//
// The RenderBuffer probably has a tree of components
// with children and elements, if only to track comment
// references.
// Component inclusions are also calculated, so their expressions
// must be sent down. Components must also be serialized on the
// wire. Argument change leads to update, of course.
// Are Component class names in templates resolved? Maybe.
// Assuming so, the test for whether a class has changed is
// comparing the resolved constructor names.