Skip to content

Instantly share code, notes, and snippets.

@bendlas
Created March 11, 2013 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendlas/5137917 to your computer and use it in GitHub Desktop.
Save bendlas/5137917 to your computer and use it in GitHub Desktop.
(def path-cache (atom {}))
(defn load-cached [path]
(if-let [ret (get @path-cache path)]
ret
(let [ret (cell nil)]
(swap! path-cache assoc path ret)
(XhrIo/send path
(fn [e]
(case (.. e -target getStatus)
200 (reset! ret (.. e -target getResponseText))
(log "ERROR" "Request to" path e)))
"GET")
ret)))
;; in this case, html-to-dom is passed a cell object
(def overlay
(cell (when-let [html (load-cached "/_static/html/backend-overlay.html")]
(let [dom (domina/html-to-dom html)]
(at js/document
["body"] (append dom))
dom))))
;; in this case, html-to-dom is passed a nil from the first transition
(def overlay
(let [html (load-cached "/_static/html/backend-overlay.html")]
(cell (when html
(let [dom (domina/html-to-dom html)]
(at js/document
["body"] (append dom))
dom)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment