View difference between Paste ID: TtgfwTvN and 1K6cFNw8
SHOW: | | - or go back to the newest paste.
1
(ns hello_seymore.core
2
  (:require [sablono.core :as sab]))
3
4-
(def app-state (atom { :likes 0}))
4+
(defonce app-state (atom {:likes 0})) ;that way figwheel will not ruin your state on reload
5
6
7
(defn like-seymore [data]
8
  (sab/html [:div
9
             [:h1 "Behold. The mighty counter. Clicked " (:likes @data) " times"]
10
             [:div [:a {:href "#"
11
                        :onClick #(swap! data update-in [:likes] inc)}
12-
                    "Click it"]]]))
12+
                    "Click it"]
13
                   [:a {:href "#" :onClick #(swap! data update-in [:likes] dec)} "Dec it"] ]]))
14
15
16
17
(defn render! []
18
  (.render js/React
19
           (like-seymore app-state)
20
           (.getElementById js/document "app")))
21
22
23
(add-watch app-state :on-change (fn [_ _ _ _] (render!)))
24
25
(render!)