   (:require-macros [cljs.core.async.macros :refer [go]])
   (:require [goog.dom :as dom]
             [goog.events :as events]
-            [cljs.core.async :as async :refer [<! >! chan timeout sliding-buffer mapcat<
+            [cljs.core.async :as async :refer [<! >! chan timeout sliding-buffer map<
                                                onto-chan]]
             [playmary.util :as util]
             [playmary.scales :as scales]))


(defn touches
  [canvas-id type]
  (mapcat< touch-data->touches (util/listen (dom/getElement canvas-id) type)))

(defn scrolling-touch?
  [touches cur-t]

                  (> (.abs js/Math (- (-> prev-t :position :y) (-> cur-t :position :y)))
                     10))))))

(defmulti handle-touches (fn [new-touches cur-touches out-c] (-> new-touches first :type)))

(defmethod handle-touches "touchstart"
  [new-touches cur-touches _]
  (go
   (merge cur-touches (zipmap (map :touch-id new-touches) new-touches))))

(defmethod handle-touches "touchmove"
  [new-touches cur-touches out-c]
  (go
   (if-let [scroll (->> new-touches
                        (filter (partial scrolling-touch? cur-touches))
                        (map (fn [{touch-id :touch-id :as t}]
                               (assoc t :y-distance
                                      (- (get-in cur-touches [touch-id :position :y])
                                         (get-in t [:position :y])))))
                        (sort-by :y-distance >)
                        first)]
     (do (>! out-c scroll)
         (assoc cur-touches (scroll :touch-id) scroll))
     cur-touches)))

(defmethod handle-touches "touchend"
  [new-touches cur-touches _]
  (go
   (merge cur-touches (zipmap (map :touch-id new-touches) new-touches))))

(defn emit-touch?
  [{t-type :type t-ticks :ticks} touches]
