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
(use 'clojure.core.async) | |
;this is the function you want to use | |
(defn lazy-channels [chs] | |
(lazy-seq | |
(cons (first (alts!! chs)) | |
(recur chs)))) | |
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
(ns sexp-css.core) | |
(defn- wrap [forms] (str "{" forms "}")) | |
(defn map-to-form [m] (let [outer-forms (reduce (fn [out-vec [k v]] (conj out-vec (str (name k) " : " v))) [] m) inner-forms (->> outer-forms (interpose ";") (apply str))] (wrap inner-forms))) | |
(defmacro defrule [selector & forms] `(str ~selector (apply map-to-form (vector ~@forms)))) | |
(defn px [n] (when (number? n) (str n "px"))) | |
(defn mixin [rule & forms] (merge rule (into {} forms))) | |
(def my-mixin | |
{:height "20px" | |
:width "100px"}) |
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
(defn debounce | |
([f] (debounce f 1000)) | |
([f timeout] | |
(let [id (atom nil)] | |
(fn [evt] | |
(if (not (nil? @id)) | |
(js/clearTimeout @id)) | |
(reset! id (js/setTimeout | |
(partial f evt) | |
timeout)))))) |