Skip to content

Instantly share code, notes, and snippets.

@jwhitlark
Created June 20, 2014 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhitlark/707f9fb5b379b39c51a5 to your computer and use it in GitHub Desktop.
Save jwhitlark/707f9fb5b379b39c51a5 to your computer and use it in GitHub Desktop.
Scrubbing Ints: Second attempt
(defn scrubbing-int-app-event-view-2 [app owner]
(reify
om/IInitState
(init-state [_]
{:capturing false
:start-x nil})
om/IWillMount
(will-mount [_]
(let [mouse-chan (async/map (fn [e] {:x (.-clientX e)
:type (.-type e)})
[(listen js/window EventType.MOUSEMOVE EventType.MOUSEUP)])]
(go (while true?
(let [evt (<! mouse-chan)]
(if (om/get-state owner :capturing)
(case (:type evt)
"mousemove" (let [difference (- (:x evt) (om/get-state owner :start-x))]
(om/transact! app :my-val (partial + difference))
(om/set-state! owner :start-x (:x evt)))
"mouseup" (set-states! owner {:capturing false :start-x nil}))))))))
om/IRenderState
(render-state [_ state]
(dom/div nil
(dom/span #js { :style #js {:color (if (:capturing state) "#00f" "#000")
:border-bottom "1px dotted #00f"
:cursor "col-resize"
:-webkit-user-select "none"}
:onMouseDown #(set-states! owner {:capturing true :start-x (.-clientX %)})}
(str "Current state is: " state ", Current app val is: " (:my-val app)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment