Skip to content

Instantly share code, notes, and snippets.

@DarrenN
Last active December 30, 2015 19:29
Show Gist options
  • Save DarrenN/7874116 to your computer and use it in GitHub Desktop.
Save DarrenN/7874116 to your computer and use it in GitHub Desktop.
Using core.async to test inserting/removing a crapton of DOM nodes to make sure domina properly remove them from memory - http://cljsfiddle.net/fiddle/DarrenN.dom.test
(ns DarrenN.dom.test
(:require [cljs.core.async :refer (<! >! chan put! take! alts! timeout close! dropping-buffer sliding-buffer)]
[domina :as dom]
[domina.events :as events]
[domina.css :as css]
[hiccups.runtime :as hiccupsrt])
(:require-macros [cljs.core.async.macros :refer (go alt!)]
[hiccups.core :as hiccups]))
(defn make-style []
(let [rgb [(rand 255) (rand 255) (rand 255)]]
(str "background: rgb(" (clojure.string/join "," (map Math/floor rgb)) ")")))
(defn make-box [id ch]
(let [box-id (str "box_" id)
ul (dom/by-id "list")]
(dom/append! ul (hiccups/html [:li {:id box-id :style (make-style)}]))
(put! ch box-id)))
(def in (chan))
(def out (chan))
(go
(while true
(let [o out]
(<! (timeout 100))
(dom/detach! (dom/by-id (<! o))))))
(go
(while true
(let [i in
o out]
;(<! (timeout 10))
(make-box (<! i) o))))
(loop [x 1020]
(when (>= x 0)
(put! in x)
(recur (dec x))))
<ul id="list"></ul>
ul {
padding: 0;
margin: 0;
}
li {
display: inline-block;
list-style-type: none;
width: 20px;
height: 20px;
margin: 1px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment