Created
December 11, 2016 07:36
-
-
Save craftybones/77f0e020a1a267230b34a5623d83b471 to your computer and use it in GitHub Desktop.
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 learning-reagent.core | |
(:require [reagent.core :as reagent])) | |
;; ------------------------- | |
;; Views | |
(defn fibo | |
([] (fibo 1 1)) | |
([s1 s2] (lazy-seq (cons s1 (fibo s2 (+ s1 s2)))))) | |
(defn fibo-container | |
[f] | |
[:div "Fibo: " (first @f)]) | |
(defn spinner-container | |
[s] | |
[:div (map (fn [c] [:div {:class c}]) (take 3 @s))]) | |
(defn sequence-cycler | |
[s f t] | |
(let [foo (reagent/atom s)] | |
(fn [s] | |
(js/setTimeout #(swap! foo rest) t) | |
(f foo)))) | |
(defn top-container [] | |
[:div | |
[:div [sequence-cycler (fibo) fibo-container 1000]] | |
[:div [sequence-cycler (cycle [:red :black :black]) spinner-container 300]]]) | |
(defn mount-root [] | |
(reagent/render [top-container] (.getElementById js/document "app"))) | |
(defn init! [] | |
(mount-root)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment