Skip to content

Instantly share code, notes, and snippets.

@jwhitlark
Created June 20, 2014 20:30
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/0081c0b479591ce1b3c7 to your computer and use it in GitHub Desktop.
Save jwhitlark/0081c0b479591ce1b3c7 to your computer and use it in GitHub Desktop.
Scrubbing ints: first attempt
(defn scrubbing-int-state-view [app owner]
(let [start-capturing #(do (om/set-state! owner :capturing true)
(om/set-state! owner :start-x (.-clientX %)))
stop-capturing #(do (om/set-state! owner :capturing false)
(om/set-state! owner :start-x nil))]
(reify
om/IInitState
(init-state [_]
{:my-val 0
:capturing false
:start-x nil})
om/IRenderState
(render-state [_ state]
(dom/div nil
(dom/span #js { :style #js {:cursor "col-resize"
:-webkit-user-select "none"}
:onMouseDown start-capturing
:onMouseMove #(if (:capturing state) (let [x (.-clientX %)
difference (- x (om/get-state owner :start-x))]
(om/update-state! owner :my-val (partial + difference))
(om/set-state! owner :start-x x)))
:onMouseUp stop-capturing
:onMouseOut stop-capturing
}
(str "Current value is: " (:my-val state))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment