refactor(core): remove more misc unused utilities from DomAdapters (#32291)
PR Close #32291
This commit is contained in:
parent
f3e4cb491e
commit
b094936d72
@ -75,23 +75,10 @@ const nodeContains: (this: Node, other: Node) => boolean = (() => {
|
|||||||
*/
|
*/
|
||||||
/* tslint:disable:requireParameterType no-console */
|
/* tslint:disable:requireParameterType no-console */
|
||||||
export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||||
parse(templateHtml: string) { throw new Error('parse not implemented'); }
|
|
||||||
static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); }
|
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; }
|
setProperty(el: Node, name: string, value: any) { (<any>el)[name] = value; }
|
||||||
getProperty(el: Node, name: string): any { return (<any>el)[name]; }
|
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 {
|
log(error: string): void {
|
||||||
if (window.console) {
|
if (window.console) {
|
||||||
window.console.log && window.console.log(error);
|
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); }
|
querySelector(el: HTMLElement, selector: string): any { return el.querySelector(selector); }
|
||||||
querySelectorAll(el: any, selector: string): any[] { return el.querySelectorAll(selector); }
|
querySelectorAll(el: any, selector: string): any[] { return el.querySelectorAll(selector); }
|
||||||
onAndCancel(el: Node, evt: any, listener: any): Function {
|
onAndCancel(el: Node, evt: any, listener: any): Function {
|
||||||
|
@ -31,26 +31,23 @@ export function setRootDomAdapter(adapter: DomAdapter) {
|
|||||||
* can introduce XSS risks.
|
* can introduce XSS risks.
|
||||||
*/
|
*/
|
||||||
export abstract class DomAdapter {
|
export abstract class DomAdapter {
|
||||||
abstract hasProperty(element: any, name: string): boolean;
|
// Needs Domino-friendly test utility
|
||||||
abstract setProperty(el: Element, name: string, value: any): any;
|
|
||||||
abstract getProperty(el: Element, name: string): any;
|
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 log(error: any): any;
|
||||||
abstract logGroup(error: any): any;
|
abstract logGroup(error: any): any;
|
||||||
abstract logGroupEnd(): 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
|
// Used by Meta
|
||||||
|
abstract querySelectorAll(el: any, selector: string): any[];
|
||||||
abstract remove(el: any): Node;
|
abstract remove(el: any): Node;
|
||||||
abstract getAttribute(element: any, attribute: string): string|null;
|
abstract getAttribute(element: any, attribute: string): string|null;
|
||||||
|
|
||||||
// Used by platform-server
|
// 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 nextSibling(el: any): Node|null;
|
||||||
abstract parentElement(el: any): Node|null;
|
abstract parentElement(el: any): Node|null;
|
||||||
abstract clearNodes(el: any): any;
|
abstract clearNodes(el: any): any;
|
||||||
|
@ -46,8 +46,6 @@ export class DominoAdapter extends BrowserDomAdapter {
|
|||||||
|
|
||||||
private static defaultDoc: Document;
|
private static defaultDoc: Document;
|
||||||
|
|
||||||
logError(error: string) { console.error(error); }
|
|
||||||
|
|
||||||
log(error: string) {
|
log(error: string) {
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -59,15 +57,6 @@ export class DominoAdapter extends BrowserDomAdapter {
|
|||||||
|
|
||||||
supportsDOMEvents(): boolean { return false; }
|
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 {
|
createHtmlDocument(): HTMLDocument {
|
||||||
return parseDocument('<html><head><title>fakeTitle</title></head><body></body></html>');
|
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 {
|
getProperty(el: Element, name: string): any {
|
||||||
if (name === 'href') {
|
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.
|
// attribute value.
|
||||||
return this.getAttribute(el, 'href');
|
return this.getAttribute(el, 'href');
|
||||||
} else if (name === 'innerText') {
|
} else if (name === 'innerText') {
|
||||||
|
@ -16,15 +16,6 @@ import {ɵDomAdapter as DomAdapter, ɵsetRootDomAdapter as setRootDomAdapter} fr
|
|||||||
export class WorkerDomAdapter extends DomAdapter {
|
export class WorkerDomAdapter extends DomAdapter {
|
||||||
static makeCurrent() { setRootDomAdapter(new WorkerDomAdapter()); }
|
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) {
|
log(error: any) {
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -33,7 +24,12 @@ export class WorkerDomAdapter extends DomAdapter {
|
|||||||
logGroup(error: any) {
|
logGroup(error: any) {
|
||||||
if (console.group) {
|
if (console.group) {
|
||||||
console.group(error);
|
console.group(error);
|
||||||
this.logError(error);
|
if (console.error) {
|
||||||
|
console.error(error);
|
||||||
|
} else {
|
||||||
|
// tslint:disable-next-line:no-console
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.log(error);
|
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'; }
|
setProperty(el: Element, name: string, value: any) { throw 'not implemented'; }
|
||||||
getProperty(el: Element, name: string): 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'; }
|
querySelector(el: any, selector: string): HTMLElement { throw 'not implemented'; }
|
||||||
querySelectorAll(el: any, selector: string): any[] { throw 'not implemented'; }
|
querySelectorAll(el: any, selector: string): any[] { throw 'not implemented'; }
|
||||||
onAndCancel(el: any, evt: any, listener: any): Function { throw 'not implemented'; }
|
onAndCancel(el: any, evt: any, listener: any): Function { throw 'not implemented'; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user