-
-
Save matklad/d1ad3375945ad21de97a to your computer and use it in GitHub Desktop.
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
(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 |
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
(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