Last active
December 30, 2015 19:29
-
-
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
This file contains hidden or 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
(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)))) |
This file contains hidden or 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
<ul id="list"></ul> |
This file contains hidden or 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
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