message: Rework state utils
diff: import { noop } from './utils'
  -import { CommonGestureState, Coordinates, State, DistanceAngle, Vector2 } from '../types'
  +import { CommonGestureState, Coordinates, State, DistanceAngle, Vector2, DragState } from '../types'
  -export function getInitialState(): State {
  - // common initial state for all gestures
  - const initialCommon: CommonGestureState = {
  +function getInitial<T>(mixed: T): T & CommonGestureState {
  + return {
  _active: false,
  _blocked: false,
  _intentional: [false, false],
  @@ -32,28 +31,14 @@ export function getInitialState(): State {
  canceled: false,
  memo: undefined,
  args: undefined,
  + ...mixed
  }
  -
  - // initial state for coordinates-based gestures
  - const initialCoordinates: Coordinates = {
  - axis: undefined,
  - xy: [0, 0] as Vector2,
  - vxvy: [0, 0] as Vector2,
  - velocity: 0,
  - distance: 0,
  }
  - // initial state for distance and angle-based gestures (pinch)
  - const initialDistanceAngle: DistanceAngle = {
  - da: [0, 0] as Vector2,
  - vdva: [0, 0] as Vector2,
  - origin: undefined,
  - turns: 0,
  - }
  - // initial state object (used by the gesture controller)
  - return {
  - shared: {
  +export function getInitialState(): State {
  +
  + const shared = {
  hovering: false,
  scrolling: false,
  wheeling: false,
  @@ -67,18 +52,51 @@ export function getInitialState(): State {
  altKey: false,
  metaKey: false,
  ctrlKey: false,
  - },
  - drag: {
  - ...initialCommon,
  - ...initialCoordinates,
  + }
  +
  + const drag = getInitial<DragState & Coordinates>({
  + axis: undefined,
  + xy: [0, 0] as Vector2,
  + vxvy: [0, 0] as Vector2,
  + velocity: 0,
  + distance: 0,
  _isTap: true,
  _delayedEvent: false,
  tap: false,
  swipe: [0, 0],
  - },
  - pinch: { ...initialCommon, ...initialDistanceAngle },
  - wheel: { ...initialCommon, ...initialCoordinates },
  - move: { ...initialCommon, ...initialCoordinates },
  - scroll: { ...initialCommon, ...initialCoordinates },
  - }
  + })
  +
  + const pinch = getInitial<DistanceAngle>({
  + da: [0, 0] as Vector2,
  + vdva: [0, 0] as Vector2,
  + origin: undefined,
  + turns: 0,
  + })
  +
  + const wheel = getInitial<Coordinates>({
  + axis: undefined,
  + xy: [0, 0] as Vector2,
  + vxvy: [0, 0] as Vector2,
  + velocity: 0,
  + distance: 0,
  + })
  +
  + const move = getInitial<Coordinates>({
  + axis: undefined,
  + xy: [0, 0] as Vector2,
  + vxvy: [0, 0] as Vector2,
  + velocity: 0,
  + distance: 0,
  + })
  +
  + const scroll = getInitial<Coordinates>({
  + axis: undefined,
  + xy: [0, 0] as Vector2,
  + vxvy: [0, 0] as Vector2,
  + velocity: 0,
  + distance: 0,
  + })
  +
  +
  + return { shared, drag, pinch, wheel, move, scroll }
  }
  