Skip to content

Commit 3e899c6

Browse files
committed
refactor(platform-browser): avoid mutable exports.
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).
1 parent 0cd8431 commit 3e899c6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

packages/platform-browser/testing/src/browser_util.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import {ɵgetDOM as getDOM} from '@angular/common';
1010
import {NgZone, ɵglobal as global} from '@angular/core';
1111

12-
export let browserDetection: BrowserDetection;
13-
1412
export class BrowserDetection {
1513
private _overrideUa: string|null;
1614
private get _ua(): string {
@@ -21,7 +19,7 @@ export class BrowserDetection {
2119
return getDOM() ? getDOM().getUserAgent() : '';
2220
}
2321

24-
static setup() { browserDetection = new BrowserDetection(null); }
22+
static setup() { return new BrowserDetection(null); }
2523

2624
constructor(ua: string|null) { this._overrideUa = ua; }
2725

@@ -88,7 +86,7 @@ export class BrowserDetection {
8886
}
8987
}
9088

91-
BrowserDetection.setup();
89+
export const browserDetection: BrowserDetection = BrowserDetection.setup();
9290

9391
export function dispatchEvent(element: any, eventType: any): void {
9492
const evt: Event = getDOM().getDefaultDocument().createEvent('Event');

0 commit comments

Comments
 (0)