Skip to content

Instantly share code, notes, and snippets.

@matklad
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matklad/d1ad3375945ad21de97a to your computer and use it in GitHub Desktop.
Save matklad/d1ad3375945ad21de97a to your computer and use it in GitHub Desktop.
(def app (atom {:code ""
:state :initial
:advice nil
:active-line nil
:timer 0} ;; this increments every 200ms...
:validator (fn [{:keys [state advice]}]
(or (#{:checked :loading} state)
(nil? advice)))))
;; factor out render-loading
(defn render-result [node {:keys [state advice timer]}]
(log "render-result")
(let [transform (if (= state :loading) ef/remove-class ef/add-class)]
(ef/at node
".advice"
(ef/content
(cond
(= state :initial) "Paste some clojure code"
(= state :broken) "Failed to check the code =(\nAre parenthesis balanced?"
(empty? advice) "Looks OK to me"
:default (map advice-snip advice)))
".result" (transform "text-info")
".loader" (transform "invisible"))))
(defn render-loading [node {time :timer}]
(log "render-loading")
(let [steps (mapv #(clojure.string/replace % " " " ")
["..." " .." " ." " " ". " ".. "])
dots (nth steps (mod time (count steps)))]
(ef/at node
".loader" (ef/content (str "Loading" dots)))))
(defaction home []
".result-wrapper" (ef/do->
(bind/bind-view app render-loading) ;; BUG
(bind/bind-view app render-result))) ;; only last binding works
(def app (atom {:code ""
:state :initial
:advice nil
:active-line nil
:timer 0} ;; this increments every 200ms...
:validator (fn [{:keys [state advice]}]
(or (#{:checked :loading} state)
(nil? advice)))))
(defn render-result [node {:keys [state advice timer]}]
(let [transform (if (= state :loading) ef/remove-class ef/add-class)
steps (mapv #(clojure.string/replace % " " " ")
["..." " .." " ." " " ". " ".. "])
dots (nth steps (mod timer (count steps)))]
(ef/at node
".advice"
(ef/content
(cond
(= state :initial) "Paste some clojure code"
(= state :broken) "Failed to check the code =(\nAre parenthesis balanced?"
(empty? advice) "Looks OK to me"
:default (map advice-snip advice)))
".result" (transform "text-info")
".loader" (ef/do-> ;; ... so it would be nice to execute only this part
(transform "invisible")
(ef/content (str "Loading" dots))))))
(defaction home []
".result-wrapper" (bind/bind-view app render-result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment