From b094936d72f46e17a8357b99d22859d3cfc6eb34 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Tue, 27 Aug 2019 16:39:33 -0700 Subject: [PATCH] refactor(core): remove more misc unused utilities from DomAdapters (#32291) PR Close #32291 --- .../src/browser/browser_adapter.ts | 14 -------------- .../platform-browser/src/dom/dom_adapter.ts | 15 ++++++--------- .../platform-server/src/domino_adapter.ts | 13 +------------ .../src/web_workers/worker/worker_adapter.ts | 19 ++++++------------- 4 files changed, 13 insertions(+), 48 deletions(-) diff --git a/packages/platform-browser/src/browser/browser_adapter.ts b/packages/platform-browser/src/browser/browser_adapter.ts index e68933fb8f..23d1223a2e 100644 --- a/packages/platform-browser/src/browser/browser_adapter.ts +++ b/packages/platform-browser/src/browser/browser_adapter.ts @@ -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) { (el)[name] = value; } getProperty(el: Node, name: string): any { return (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 { diff --git a/packages/platform-browser/src/dom/dom_adapter.ts b/packages/platform-browser/src/dom/dom_adapter.ts index b049f22947..0c9c9a5a72 100644 --- a/packages/platform-browser/src/dom/dom_adapter.ts +++ b/packages/platform-browser/src/dom/dom_adapter.ts @@ -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; diff --git a/packages/platform-server/src/domino_adapter.ts b/packages/platform-server/src/domino_adapter.ts index 04a8e23a5f..0639c20be6 100644 --- a/packages/platform-server/src/domino_adapter.ts +++ b/packages/platform-server/src/domino_adapter.ts @@ -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('fakeTitle'); } @@ -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') { diff --git a/packages/platform-webworker/src/web_workers/worker/worker_adapter.ts b/packages/platform-webworker/src/web_workers/worker/worker_adapter.ts index 903dfacdb9..f83b68d19e 100644 --- a/packages/platform-webworker/src/web_workers/worker/worker_adapter.ts +++ b/packages/platform-webworker/src/web_workers/worker/worker_adapter.ts @@ -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'; }