perf(animation): improves _progress() hot function

- progress() is the function where more time is spent during any swipe gesture
- replace iterating over the _fx properties, using an array instead
- optimize pointerCoord(), profiler showed it’s one of the most called functions
This commit is contained in:
Manu Mtz.-Almeida
2016-11-16 19:48:35 +01:00
parent 70f8a8e5eb
commit c44f6b6f2e
5 changed files with 95 additions and 78 deletions

View File

@@ -195,16 +195,18 @@ export function windowLoad(callback?: Function) {
export function pointerCoord(ev: any): PointerCoordinates {
// get coordinates for either a mouse click
// or a touch depending on the given event
let c = { x: 0, y: 0 };
if (ev) {
const touches = ev.touches && ev.touches.length ? ev.touches : [ev];
const e = (ev.changedTouches && ev.changedTouches[0]) || touches[0];
if (e) {
c.x = e.clientX || e.pageX || 0;
c.y = e.clientY || e.pageY || 0;
var changedTouches = ev.changedTouches;
if (changedTouches && changedTouches.length > 0) {
var touch = changedTouches[0];
return { x: touch.clientX, y: touch.clientY };
}
var pageX = ev.pageX;
if (pageX !== undefined) {
return { x: pageX, y: ev.pageY };
}
}
return c;
return { x: 0, y: 0 };
}
export function hasPointerMoved(threshold: number, startCoord: PointerCoordinates, endCoord: PointerCoordinates) {