refactor(platform-browser): avoid mutable exports. (#34207) (#34960)

Previously, browser_util would export a mutable `let` binding that was
initialized as a side-effect of `BrowserDetection.setup()`. This change
refactors the mutable binding into a `const` binding that is immediately
initialized in its initialized.

This is functionally equivalent, but makes it easier for module
optimizers such as Closure Compiler to track down side effects and prune
modules. It is also arguably cleaner to read (no worries about later
changes to the apparently mutable but effectively const binding).

PR Close #34207

PR Close #34960
This commit is contained in:
Martin Probst
2019-12-03 09:15:49 +01:00
committed by Andrew Kushnir
parent b9adcf9ebc
commit 8fca9b6530

View File

@ -9,8 +9,6 @@
import {ɵgetDOM as getDOM} from '@angular/common';
import {NgZone, ɵglobal as global} from '@angular/core';
export let browserDetection: BrowserDetection;
export class BrowserDetection {
private _overrideUa: string|null;
private get _ua(): string {
@ -21,7 +19,7 @@ export class BrowserDetection {
return getDOM() ? getDOM().getUserAgent() : '';
}
static setup() { browserDetection = new BrowserDetection(null); }
static setup() { return new BrowserDetection(null); }
constructor(ua: string|null) { this._overrideUa = ua; }
@ -88,7 +86,7 @@ export class BrowserDetection {
}
}
BrowserDetection.setup();
export const browserDetection: BrowserDetection = BrowserDetection.setup();
export function dispatchEvent(element: any, eventType: any): void {
const evt: Event = getDOM().getDefaultDocument().createEvent('Event');