Skip to content

Commit

Permalink
[added] validation that a value is an Event in isPointerEvent
Browse files Browse the repository at this point in the history
Summary: To ensure we don't call `event.target.setPointerCapture(event.pointerId)` on a fake `PointerEvent`.

Reviewers: O2 Material Motion, O3 Material JavaScript platform reviewers, #material_motion, featherless

Reviewed By: O2 Material Motion, #material_motion, featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D3086
  • Loading branch information
appsforartists committed Apr 24, 2017
1 parent e9dcb39 commit b2eae28
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/core/src/typeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ export function isPoint2D(value: any): value is Point2D {
}

/**
* Checks if a value is a `PointerEvent` by checking if `type` starts with
* `pointer`.
* Checks if a value is a `PointerEvent` by checking if the value is an `Event`
* whose `type` starts with `pointer`.
*
* This is useful for ensuring that `downEvent.target.setPointerCapture()` can
* be called: To avoid using the PointerEvent polyfill, a developer could
* create an object that had the subset of `PointerEvent` that we care about
* (`PartialPointerEvent`) and populate its values from `event.targetTouches`.
* However, we only need to call `setPointerCapture()` on a true `PointerEvent`,
* so `isPointerEvent(value)` needs to be able to distinguish between them.
*/
export function isPointerEvent(value: any): value is PointerEvent {
return value.type.startsWith('pointer');
return value instanceof Event && value.type.startsWith('pointer');
}

0 comments on commit b2eae28

Please sign in to comment.