feat(render): add generic view factory based on the template commands

Part of #3605
Closes #4367
This commit is contained in:
Tobias Bosch
2015-09-25 09:43:21 -07:00
parent 0ed6fc4f6b
commit 1cf45757cd
11 changed files with 906 additions and 8 deletions

View File

@ -158,7 +158,9 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
removeChild(el, node) { el.removeChild(node); }
replaceChild(el: Node, newChild, oldChild) { el.replaceChild(newChild, oldChild); }
remove(node): Node {
node.parentNode.removeChild(node);
if (node.parentNode) {
node.parentNode.removeChild(node);
}
return node;
}
insertBefore(el, node) { el.parentNode.insertBefore(node, el); }

View File

@ -221,9 +221,7 @@ class Html5LibDomAdapter implements DomAdapter {
return new Element.tag(tagName);
}
createTextNode(String text, [doc]) {
throw 'not implemented';
}
createTextNode(String text, [doc]) => new Text(text);
createScriptTag(String attrName, String attrValue, [doc]) {
throw 'not implemented';

View File

@ -276,7 +276,11 @@ export class Parse5DomAdapter extends DomAdapter {
createElement(tagName): HTMLElement {
return treeAdapter.createElement(tagName, 'http://www.w3.org/1999/xhtml', []);
}
createTextNode(text: string): Text { throw _notImplemented('createTextNode'); }
createTextNode(text: string): Text {
var t = <any>this.createComment(text);
t.type = 'text';
return t;
}
createScriptTag(attrName: string, attrValue: string): HTMLElement {
return treeAdapter.createElement("script", 'http://www.w3.org/1999/xhtml',
[{name: attrName, value: attrValue}]);
@ -424,6 +428,9 @@ export class Parse5DomAdapter extends DomAdapter {
setAttribute(element, attribute: string, value: string) {
if (attribute) {
element.attribs[attribute] = value;
if (attribute === 'class') {
element.className = value;
}
}
}
removeAttribute(element, attribute: string) {