-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PressabilityPerformanceEventEmitter
Summary: Add PressabilityPerformanceEventEmitter which allows product code / infrastructure to subscribe to touch-related performance events. Changelog: [Added][JS] Product/infra can subscribe to Pressability touch events for telemetry purposes Reviewed By: fkgozali Differential Revision: D27034835 fbshipit-source-id: e62811f641994b9eadb5cdd7391e806b6cce479a
- Loading branch information
1 parent
9c19260
commit c4c0065
Showing
3 changed files
with
74 additions
and
9 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
47 changes: 47 additions & 0 deletions
47
Libraries/Pressability/PressabilityPerformanceEventEmitter.js
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,47 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
import {type PressabilityTouchSignal as TouchSignal} from './PressabilityTypes.js'; | ||
|
||
export type PressabilityPerformanceEvent = $ReadOnly<{| | ||
signal: TouchSignal, | ||
touchDelayMs: number, | ||
|}>; | ||
export type PressabilityPerformanceEventListener = PressabilityPerformanceEvent => void; | ||
|
||
class PressabilityPerformanceEventEmitter { | ||
_listeners: Array<PressabilityPerformanceEventListener> = []; | ||
|
||
constructor() {} | ||
|
||
addListener(listener: PressabilityPerformanceEventListener): void { | ||
this._listeners.push(listener); | ||
} | ||
|
||
removeListener(listener: PressabilityPerformanceEventListener): void { | ||
const index = this._listeners.indexOf(listener); | ||
if (index > -1) { | ||
this._listeners.splice(index, 1); | ||
} | ||
} | ||
|
||
emitEvent(constructEvent: () => PressabilityPerformanceEvent): void { | ||
if (this._listeners.length === 0) { | ||
return; | ||
} | ||
|
||
const event = constructEvent(); | ||
this._listeners.forEach(listener => listener(event)); | ||
} | ||
} | ||
|
||
const PressabilityPerformanceEventEmitterSingleton: PressabilityPerformanceEventEmitter = new PressabilityPerformanceEventEmitter(); | ||
|
||
export default PressabilityPerformanceEventEmitterSingleton; |
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,18 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
export type PressabilityTouchSignal = | ||
| 'DELAY' | ||
| 'RESPONDER_GRANT' | ||
| 'RESPONDER_RELEASE' | ||
| 'RESPONDER_TERMINATED' | ||
| 'ENTER_PRESS_RECT' | ||
| 'LEAVE_PRESS_RECT' | ||
| 'LONG_PRESS_DETECTED'; |