mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
3c66b100dd
The `DomAdapter` is present in all Angular apps and its methods aren't tree shakeable. These changes remove the methods that either aren't being used anymore or were only used by our own tests. Note that these changes aren't breaking, because the adapter is an internal API. The following methods were removed: * `getProperty` - only used within our own tests. * `log` - Guaranteed to be defined on `console`. * `logGroup` and `logGroupEnd` - Only used in one place. It was in the DomAdapter for built-in null checking. * `logGroupEnd` - Only used in one place. It was placed in the DomAdapter for built in null checking. * `performanceNow` - Only used in one place that has to be invoked through the browser console. * `supportsCookies` - Unused. * `getCookie` - Unused. * `getLocation` and `getHistory` - Only used in one place which appears to have access to the DOM already, because it had direct accesses to `window`. Furthermore, even if this was being used in a non-browser context already, the `DominoAdapter` was set up to throw an error. The following APIs were changed to be more compact: * `supportsDOMEvents` - Changed to a readonly property. * `remove` - No longer returns the removed node. PR Close #41102
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
let _DOM: DomAdapter = null!;
|
|
|
|
export function getDOM(): DomAdapter {
|
|
return _DOM;
|
|
}
|
|
|
|
export function setDOM(adapter: DomAdapter) {
|
|
_DOM = adapter;
|
|
}
|
|
|
|
export function setRootDomAdapter(adapter: DomAdapter) {
|
|
if (!_DOM) {
|
|
_DOM = adapter;
|
|
}
|
|
}
|
|
|
|
/* tslint:disable:requireParameterType */
|
|
/**
|
|
* Provides DOM operations in an environment-agnostic way.
|
|
*
|
|
* @security Tread carefully! Interacting with the DOM directly is dangerous and
|
|
* can introduce XSS risks.
|
|
*/
|
|
export abstract class DomAdapter {
|
|
// Needs Domino-friendly test utility
|
|
abstract dispatchEvent(el: any, evt: any): any;
|
|
abstract readonly supportsDOMEvents: boolean;
|
|
|
|
// Used by Meta
|
|
abstract remove(el: any): void;
|
|
abstract createElement(tagName: any, doc?: any): HTMLElement;
|
|
abstract createHtmlDocument(): HTMLDocument;
|
|
abstract getDefaultDocument(): Document;
|
|
|
|
// Used by By.css
|
|
abstract isElementNode(node: any): boolean;
|
|
|
|
// Used by Testability
|
|
abstract isShadowRoot(node: any): boolean;
|
|
|
|
// Used by KeyEventsPlugin
|
|
abstract onAndCancel(el: any, evt: any, listener: any): Function;
|
|
|
|
// Used by PlatformLocation and ServerEventManagerPlugin
|
|
abstract getGlobalEventTarget(doc: Document, target: string): any;
|
|
|
|
// Used by PlatformLocation
|
|
abstract getBaseHref(doc: Document): string|null;
|
|
abstract resetBaseElement(): void;
|
|
|
|
// TODO: remove dependency in DefaultValueAccessor
|
|
abstract getUserAgent(): string;
|
|
|
|
// Used in the legacy @angular/http package which has some usage in g3.
|
|
abstract getCookie(name: string): string|null;
|
|
}
|