-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not mark listeners as
passive
if they are not supported and…
… reduce DOM lookups
- Loading branch information
Showing
7 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Component, HostBinding } from '@angular/core'; | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'gantt-drag-backdrop', | ||
templateUrl: `./drag-backdrop.component.html` | ||
templateUrl: `./drag-backdrop.component.html`, | ||
host: { | ||
class: 'gantt-drag-backdrop' | ||
} | ||
}) | ||
export class GanttDragBackdropComponent { | ||
@HostBinding('class.gantt-drag-backdrop') backdropClass = true; | ||
} | ||
export class GanttDragBackdropComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** Cached result of whether the user's browser supports passive event listeners. */ | ||
let supportsPassiveEvents: boolean; | ||
|
||
/** | ||
* Checks whether the user's browser supports passive event listeners. | ||
* See: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md | ||
*/ | ||
export function supportsPassiveEventListeners(): boolean { | ||
if (supportsPassiveEvents == null && typeof window !== 'undefined') { | ||
try { | ||
window.addEventListener( | ||
'test', | ||
null!, | ||
Object.defineProperty({}, 'passive', { | ||
get: () => (supportsPassiveEvents = true) | ||
}) | ||
); | ||
} finally { | ||
supportsPassiveEvents = supportsPassiveEvents || false; | ||
} | ||
} | ||
|
||
return supportsPassiveEvents; | ||
} | ||
|
||
/** | ||
* Normalizes an `AddEventListener` object to something that can be passed | ||
* to `addEventListener` on any browser, no matter whether it supports the | ||
* `options` parameter. | ||
*/ | ||
export function normalizePassiveListenerOptions(options: AddEventListenerOptions): AddEventListenerOptions | boolean { | ||
return supportsPassiveEventListeners() ? options : !!options.capture; | ||
} | ||
|
||
/** Options used to bind passive event listeners. */ | ||
export const passiveListenerOptions = <AddEventListenerOptions>normalizePassiveListenerOptions({ passive: true }); |