Skip to content

Commit

Permalink
feat(rstream-gestures): enable TS strict compiler flags (refactor)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 4, 2019
1 parent 6e3fec8 commit 412dd46
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/rstream-gestures/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IID } from "@thi.ng/api";
import { fromEvent, merge, StreamMerge } from "@thi.ng/rstream";
import { fromDOMEvent, merge, StreamMerge } from "@thi.ng/rstream";
import { map } from "@thi.ng/transducers";

export const enum GestureType {
Expand Down Expand Up @@ -28,6 +28,8 @@ export interface GestureEvent {
[1]: GestureInfo;
}

type UIEvent = MouseEvent | TouchEvent | WheelEvent;

export interface GestureStreamOpts extends IID<string> {
/**
* Event listener options (see standard `addEventListener()`)
Expand Down Expand Up @@ -131,7 +133,7 @@ export const gestureStream = (
let zoom = Math.min(Math.max(opts.zoom, opts.minZoom), opts.maxZoom);
const dpr = window.devicePixelRatio || 1;

return merge({
return merge<UIEvent, GestureEvent>({
id: opts.id,
src: [
"mousedown",
Expand All @@ -142,26 +144,27 @@ export const gestureStream = (
"touchend",
"touchcancel",
"wheel"
].map((e) => fromEvent(el, e, opts.eventOpts)),
xform: map((e: MouseEvent | TouchEvent | WheelEvent) => {
let evt, type;
].map((e) => fromDOMEvent(el, <any>e, opts.eventOpts)),
xform: map((e) => {
let evt: { clientX: number; clientY: number };
let type: any;
opts.preventDefault && e.preventDefault();
if ((<TouchEvent>e).touches) {
type = {
type = (<any>{
touchstart: GestureType.START,
touchmove: GestureType.DRAG,
touchend: GestureType.END,
touchcancel: GestureType.END
}[e.type];
})[e.type];
evt = (<TouchEvent>e).changedTouches[0];
} else {
type = {
type = (<any>{
mousedown: GestureType.START,
mousemove: isDown ? GestureType.DRAG : GestureType.MOVE,
mouseup: GestureType.END,
wheel: GestureType.ZOOM
}[e.type];
evt = e;
})[e.type];
evt = <any>e;
}
const pos = [evt.clientX | 0, evt.clientY | 0];
if (opts.local) {
Expand Down

0 comments on commit 412dd46

Please sign in to comment.