Created
June 20, 2014 20:30
-
-
Save jwhitlark/0081c0b479591ce1b3c7 to your computer and use it in GitHub Desktop.
Scrubbing ints: first attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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