Skip to content

Instantly share code, notes, and snippets.

@cpetzold
Created December 20, 2012 21:42
Show Gist options
  • Save cpetzold/4348814 to your computer and use it in GitHub Desktop.
Save cpetzold/4348814 to your computer and use it in GitHub Desktop.
(def initial-state
{:mode :search
:input ""
:completes []})
(def state (atom initial-state))
(def mode-map
{:search
{:placeholder "Search..."
:input-watch :search-watch
:shadow-value suggest-result
:key-handle search}
:tweet
{:placeholder "Tweet..."
:input-watch :tweet-watch
:shadow-value remaining-characters}})
(defn render [state]
(let [{:keys [input completes mode]} state
params (mode-map mode)]
[:div#container
[:button#toggle-mode (str "Switch to " (name (other-mode mode)) " mode")]
[:div#input-wrapper
[:textarea#input {:watch (:input-watch params)
:value input
:autofocus true
:placeholder (:placeholder params)}]
[:textarea#shadow {:value ((:shadow-value params) state)
:disabled true}]]
[:div#results
{:class (when (or (= mode :tweet) (empty? completes)) "hide")}
(map #(auto-result input %) completes)]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment