mirror of https://github.com/status-im/reagent.git
atom -> r/atom in examples
This commit is contained in:
parent
3a93bd6a49
commit
8abb75b95d
|
@ -55,7 +55,8 @@
|
||||||
(string/join ")|(" [comment-p str-p open-p
|
(string/join ")|(" [comment-p str-p open-p
|
||||||
close-p meta-p iden-p any-p])
|
close-p meta-p iden-p any-p])
|
||||||
")"))
|
")"))
|
||||||
keyw-re #"^:"]
|
keyw-re #"^:"
|
||||||
|
qualif-re #"^r/"]
|
||||||
(for [[s comment str-litt open close met iden any] (re-seq patt src)]
|
(for [[s comment str-litt open close met iden any] (re-seq patt src)]
|
||||||
(cond
|
(cond
|
||||||
comment [:comment s]
|
comment [:comment s]
|
||||||
|
@ -66,6 +67,7 @@
|
||||||
iden (cond
|
iden (cond
|
||||||
(re-find keyw-re s) [:keyw s]
|
(re-find keyw-re s) [:keyw s]
|
||||||
(builtins s) [:builtin s]
|
(builtins s) [:builtin s]
|
||||||
|
(re-find qualif-re s) [:builtin s]
|
||||||
:else [:iden s])
|
:else [:iden s])
|
||||||
any [:other s]))))
|
any [:other s]))))
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
(ns simpleexample.core
|
(ns simpleexample.core
|
||||||
(:require [reagent.core :as reagent :refer [atom]]))
|
(:require [reagent.core :as r]))
|
||||||
|
|
||||||
(defonce timer (atom (js/Date.)))
|
(defonce timer (r/atom (js/Date.)))
|
||||||
|
|
||||||
(defonce time-color (atom "#f34"))
|
(defonce time-color (r/atom "#f34"))
|
||||||
|
|
||||||
(defonce time-updater (js/setInterval
|
(defonce time-updater (js/setInterval
|
||||||
#(reset! timer (js/Date.)) 1000))
|
#(reset! timer (js/Date.)) 1000))
|
||||||
|
@ -31,5 +31,5 @@
|
||||||
[color-input]])
|
[color-input]])
|
||||||
|
|
||||||
(defn ^:export run []
|
(defn ^:export run []
|
||||||
(reagent/render [simple-example]
|
(r/render [simple-example]
|
||||||
(js/document.getElementById "app")))
|
(js/document.getElementById "app")))
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
(ns todomvc.core
|
(ns todomvc.core
|
||||||
(:require [reagent.core :as reagent :refer [atom]]))
|
(:require [reagent.core :as r]))
|
||||||
|
|
||||||
(defonce todos (atom (sorted-map)))
|
(defonce todos (r/atom (sorted-map)))
|
||||||
|
|
||||||
(defonce counter (atom 0))
|
(defonce counter (r/atom 0))
|
||||||
|
|
||||||
(defn add-todo [text]
|
(defn add-todo [text]
|
||||||
(let [id (swap! counter inc)]
|
(let [id (swap! counter inc)]
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
(complete-all true)))
|
(complete-all true)))
|
||||||
|
|
||||||
(defn todo-input [{:keys [title on-save on-stop]}]
|
(defn todo-input [{:keys [title on-save on-stop]}]
|
||||||
(let [val (atom title)
|
(let [val (r/atom title)
|
||||||
stop #(do (reset! val "")
|
stop #(do (reset! val "")
|
||||||
(if on-stop (on-stop)))
|
(if on-stop (on-stop)))
|
||||||
save #(let [v (-> @val str clojure.string/trim)]
|
save #(let [v (-> @val str clojure.string/trim)]
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
nil)})])))
|
nil)})])))
|
||||||
|
|
||||||
(def todo-edit (with-meta todo-input
|
(def todo-edit (with-meta todo-input
|
||||||
{:component-did-mount #(.focus (reagent/dom-node %))}))
|
{:component-did-mount #(.focus (r/dom-node %))}))
|
||||||
|
|
||||||
(defn todo-stats [{:keys [filt active done]}]
|
(defn todo-stats [{:keys [filt active done]}]
|
||||||
(let [props-for (fn [name]
|
(let [props-for (fn [name]
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
"Clear completed " done])]))
|
"Clear completed " done])]))
|
||||||
|
|
||||||
(defn todo-item []
|
(defn todo-item []
|
||||||
(let [editing (atom false)]
|
(let [editing (r/atom false)]
|
||||||
(fn [{:keys [id done title]}]
|
(fn [{:keys [id done title]}]
|
||||||
[:li {:class (str (if done "completed ")
|
[:li {:class (str (if done "completed ")
|
||||||
(if @editing "editing"))}
|
(if @editing "editing"))}
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
:on-stop #(reset! editing false)}])])))
|
:on-stop #(reset! editing false)}])])))
|
||||||
|
|
||||||
(defn todo-app [props]
|
(defn todo-app [props]
|
||||||
(let [filt (atom :all)]
|
(let [filt (r/atom :all)]
|
||||||
(fn []
|
(fn []
|
||||||
(let [items (vals @todos)
|
(let [items (vals @todos)
|
||||||
done (->> items (filter :done) count)
|
done (->> items (filter :done) count)
|
||||||
|
@ -104,5 +104,5 @@
|
||||||
[:p "Double-click to edit a todo"]]]))))
|
[:p "Double-click to edit a todo"]]]))))
|
||||||
|
|
||||||
(defn ^:export run []
|
(defn ^:export run []
|
||||||
(reagent/render [todo-app]
|
(r/render [todo-app]
|
||||||
(js/document.getElementById "app")))
|
(js/document.getElementById "app")))
|
||||||
|
|
Loading…
Reference in New Issue