refactor(core): remove more misc unused utilities from DomAdapters (#32291)

PR Close #32291
This commit is contained in:
Kara Erickson 2019-08-27 16:39:33 -07:00 committed by Miško Hevery
parent f3e4cb491e
commit b094936d72
4 changed files with 13 additions and 48 deletions

View File

@ -75,23 +75,10 @@ const nodeContains: (this: Node, other: Node) => boolean = (() => {
*/
/* tslint:disable:requireParameterType no-console */
export class BrowserDomAdapter extends GenericBrowserDomAdapter {
parse(templateHtml: string) { throw new Error('parse not implemented'); }
static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); }
hasProperty(element: Node, name: string): boolean { return name in element; }
setProperty(el: Node, name: string, value: any) { (<any>el)[name] = value; }
getProperty(el: Node, name: string): any { return (<any>el)[name]; }
// TODO(tbosch): move this into a separate environment class once we have it
logError(error: string): void {
if (window.console) {
if (console.error) {
console.error(error);
} else {
console.log(error);
}
}
}
log(error: string): void {
if (window.console) {
window.console.log && window.console.log(error);
@ -110,7 +97,6 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
}
}
contains(nodeA: any, nodeB: any): boolean { return nodeContains.call(nodeA, nodeB); }
querySelector(el: HTMLElement, selector: string): any { return el.querySelector(selector); }
querySelectorAll(el: any, selector: string): any[] { return el.querySelectorAll(selector); }
onAndCancel(el: Node, evt: any, listener: any): Function {

View File

@ -31,26 +31,23 @@ export function setRootDomAdapter(adapter: DomAdapter) {
* can introduce XSS risks.
*/
export abstract class DomAdapter {
abstract hasProperty(element: any, name: string): boolean;
abstract setProperty(el: Element, name: string, value: any): any;
// Needs Domino-friendly test utility
abstract getProperty(el: Element, name: string): any;
abstract dispatchEvent(el: any, evt: any): any;
abstract logError(error: any): any;
// Used by router
abstract log(error: any): any;
abstract logGroup(error: any): any;
abstract logGroupEnd(): any;
abstract contains(nodeA: any, nodeB: any): boolean;
abstract parse(templateHtml: string): any;
abstract querySelector(el: any, selector: string): any;
abstract querySelectorAll(el: any, selector: string): any[];
abstract dispatchEvent(el: any, evt: any): any;
// Used by Meta
abstract querySelectorAll(el: any, selector: string): any[];
abstract remove(el: any): Node;
abstract getAttribute(element: any, attribute: string): string|null;
// Used by platform-server
abstract setProperty(el: Element, name: string, value: any): any;
abstract querySelector(el: any, selector: string): any;
abstract nextSibling(el: any): Node|null;
abstract parentElement(el: any): Node|null;
abstract clearNodes(el: any): any;

View File

@ -46,8 +46,6 @@ export class DominoAdapter extends BrowserDomAdapter {
private static defaultDoc: Document;
logError(error: string) { console.error(error); }
log(error: string) {
// tslint:disable-next-line:no-console
console.log(error);
@ -59,15 +57,6 @@ export class DominoAdapter extends BrowserDomAdapter {
supportsDOMEvents(): boolean { return false; }
contains(nodeA: any, nodeB: any): boolean {
let inner = nodeB;
while (inner) {
if (inner === nodeA) return true;
inner = inner.parent;
}
return false;
}
createHtmlDocument(): HTMLDocument {
return parseDocument('<html><head><title>fakeTitle</title></head><body></body></html>');
}
@ -86,7 +75,7 @@ export class DominoAdapter extends BrowserDomAdapter {
getProperty(el: Element, name: string): any {
if (name === 'href') {
// Domino tries tp resolve href-s which we do not want. Just return the
// Domino tries to resolve href-s which we do not want. Just return the
// attribute value.
return this.getAttribute(el, 'href');
} else if (name === 'innerText') {

View File

@ -16,15 +16,6 @@ import {ɵDomAdapter as DomAdapter, ɵsetRootDomAdapter as setRootDomAdapter} fr
export class WorkerDomAdapter extends DomAdapter {
static makeCurrent() { setRootDomAdapter(new WorkerDomAdapter()); }
logError(error: any) {
if (console.error) {
console.error(error);
} else {
// tslint:disable-next-line:no-console
console.log(error);
}
}
log(error: any) {
// tslint:disable-next-line:no-console
console.log(error);
@ -33,7 +24,12 @@ export class WorkerDomAdapter extends DomAdapter {
logGroup(error: any) {
if (console.group) {
console.group(error);
this.logError(error);
if (console.error) {
console.error(error);
} else {
// tslint:disable-next-line:no-console
console.log(error);
}
} else {
// tslint:disable-next-line:no-console
console.log(error);
@ -46,12 +42,9 @@ export class WorkerDomAdapter extends DomAdapter {
}
}
contains(nodeA: any, nodeB: any): boolean { throw 'not implemented'; }
hasProperty(element: any, name: string): boolean { throw 'not implemented'; }
setProperty(el: Element, name: string, value: any) { throw 'not implemented'; }
getProperty(el: Element, name: string): any { throw 'not implemented'; }
parse(templateHtml: string) { throw 'not implemented'; }
querySelector(el: any, selector: string): HTMLElement { throw 'not implemented'; }
querySelectorAll(el: any, selector: string): any[] { throw 'not implemented'; }
onAndCancel(el: any, evt: any, listener: any): Function { throw 'not implemented'; }