Update: git repo with examples
Prelude: simple clock
Scrubbing Int, Approach one: all local state
Two utility functions:
My first attempt entirely used internal state. Not terribly useful, but it set the stage.
It works entirely in the span element. Click and drag changes the value. If you drag out of the element before you release the mouse button, the state becomes inconsistent. The snippet below will let you tune the sensitivity if you use it in the :onMouseMove handler.
Now
Now
Approach two: Moving out the state
So here I've switched things to use an external atom for the value, and moved most of the logic into event listeners under IWillMount. This works correctly even if you drag off the span element. It's pretty much everything I set out to do with this.
The only drawback is the event listeners should be connected in the handler for onMouseDown, and removed when "mouseup" is received. I'll update it when I've figured out how to remove existing listeners.
Afterward: Stuff you should be looking at
- devcards are awesome, a great way to prototype this kind of stuff
- Prismatic/om-tools
- om-sweet-om-high-functional-frontend-engineering-with-clojurescript-and-react/
- Isomorphic Clojurescipt, and his example omelette
4 comments:
Thanks for the post. But it 's rather difficult to try these ideas without a Leiningen project. I tried to add the dependencies myself, lein-cljsbuild compiles but the final .html shows nothing.
Could you also share an executable project with all dependencies? Thanks!
I've created a project with the code of the examples.
You can access it via
https://www.dropbox.com/sh/9oqauimp511efmu/AADrLJhLTLRFdykUmuGDH7K8a
Juan Manuel
I added the code to a lein project, using devcards. Hope that helps.
Wow! Thank you! I constantly wanted to write on my site something like that. Can I take a portion of your post to my website?. Best natural loofah sponge service provider.
Post a Comment