Content-Length: 369389 | pFad | http://github.com/angular/angular/pull/60728/files

B5 refactor(core): reduce `navigator.userAgent` checks size by arturovt · Pull Request #60728 · angular/angular · GitHub
Skip to content

refactor(core): reduce navigator.userAgent checks size #60728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions packages/core/primitives/event-dispatch/src/event.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import {EventHandlerInfo} from './event_handler';
import {isCaptureEventType, EventType} from './event_type';
import {KeyCode} from './key_code';
import {userAgent} from './user_agent';

/**
* Gets a browser event type, if it would differ from the JSAction event type.
@@ -134,7 +135,7 @@ export function getTarget(e: Event): Element {
/**
* Whether we are on a Mac. Not pulling in useragent just for this.
*/
let isMac: boolean = typeof navigator !== 'undefined' && /Macintosh/.test(navigator.userAgent);
let isMac: boolean = /Macintosh/.test(userAgent);

/**
* Determines and returns whether the given event (which is assumed to be a
@@ -173,21 +174,13 @@ export function isModifiedClickEvent(e: Event): boolean {
}

/** Whether we are on WebKit (e.g., Chrome). */
export const isWebKit: boolean =
typeof navigator !== 'undefined' &&
!/Opera/.test(navigator.userAgent) &&
/WebKit/.test(navigator.userAgent);
export const isWebKit = !/Opera/.test(userAgent) && /WebKit/.test(userAgent);

/** Whether we are on IE. */
export const isIe: boolean =
typeof navigator !== 'undefined' &&
(/MSIE/.test(navigator.userAgent) || /Trident/.test(navigator.userAgent));
export const isIe = /MSIE/.test(userAgent) || /Trident/.test(userAgent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As IE no longer supported, why not to remove it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primitives are used in Google outside of angular apps.


/** Whether we are on Gecko (e.g., Firefox). */
export const isGecko: boolean =
typeof navigator !== 'undefined' &&
!/Opera|WebKit/.test(navigator.userAgent) &&
/Gecko/.test(navigator.product);
export const isGecko = !/Opera|WebKit/.test(userAgent) && /Gecko/.test(navigator.product);

/**
* Determines and returns whether the given element is a valid target for
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

import * as eventLib from './event';
import {EventHandlerInfo} from './event_handler';
import {userAgent} from './user_agent';

/**
* An `EventContractContainerManager` provides the common interface for managing
@@ -26,7 +27,7 @@ export interface EventContractContainerManager {
/**
* Whether the user agent is running on iOS.
*/
const isIos = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/.test(navigator.userAgent);
const isIos = /iPhone|iPad|iPod/.test(userAgent);

/**
* A class representing a container node and all the event handlers
9 changes: 9 additions & 0 deletions packages/core/primitives/event-dispatch/src/user_agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @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.dev/license
*/

export const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '';








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/angular/angular/pull/60728/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy