Created
June 28, 2012 12:17
-
-
Save robashton/3011019 to your computer and use it in GitHub Desktop.
Keyboard.clj
This file contains hidden or 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 onKeyDown [e] | |
(.log js/console "down") | |
) | |
(defn onKeyUp [e] | |
(.log js/console "up") | |
) | |
(defn hookKeyboard [] | |
(.addEventListener js/document "keydown" onKeyDown) | |
(.addEventListener js/document "keyup" onKeyUp) | |
) | |
// If left is down, (dec x) else if right is down (inc x) | |
// How do I get from the above code to being able to write the above code. | |
// Please note: I don't want to jump ahead to a pure functional solution unless it's really simple and doesn't expose too many new concepts to me - I'll be iterating on this a few times on my blog and can't just 'jump ahead'. | |
// I'd prefer to start off with shared mutated state (a map of keys to their current state for example) and then move away from that. |
Great! I saw atoms but their use looked more complicated than this - thanks for answering my specific question - hope to improve shortly. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make an top level atom, mutate that.