Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns hello_seymore.core
- (:require [sablono.core :as sab]))
- ;(defonce app-state (atom { :likes 0 }))
- ;(def exp-stack (atom { :x (atom '()) :y (atom '()) :operator (atom '()) :result 0}))
- (def x (atom { :val '() }))
- (def y (atom { :val '() }))
- (def op (atom { :val '() }))
- (def result (atom { :val '() }))
- (defn a-simple-stateful-object [x y op]
- (sab/html [:div
- ;[:h1 "Behold. The mighty counter. Clicked " (:likes @data) " times."]
- ;[:div [:a {:href "#"
- ; :onClick #(swap! data update-in [:likes] inc)}
- ; "Click the counter."]
- ; " "
- ; [:a {:href "#"
- ; :onClick #(swap! data update-in [:likes] dec)}
- ; "Reverse the arrow of time."]]
- ;[:p ""]
- [:div
- [:h2 "Let's make an adder!"]
- [:div [:a {:href "#"
- :onClick ; just the basics, ma'am.
- ; enclose an addition operator in the op atom
- #(swap! op update-in [:val] (fn [arg] (quote + arg)))}
- "+"]
- " "
- [:a {:href "#"
- :onClick ; enclose a 1 in the x atom
- #(swap! x update-in [:val] (fn [arg] (quote 1 arg)))}
- ;(swap! (:y @registers) (fn [y] (apply str y 1))))}
- "1"]
- " "
- [:a {:href "#"
- :onClick ; enclose a 2 in the y atom
- ;#(if (not (string? (:operator @registers)))
- #(swap! y update-in [:val] (fn [arg] (quote 2 arg)))}
- ;(swap! registers update-in [:y] str % 2)))}
- "2"]
- " "
- [:a {:href "#"
- :onClick ; add x and y
- #(swap! result update-in [:val] (fn [arg] (apply + (vector (:val @x) (:val @y))))) }
- "="]
- [:div
- [:p
- [:h2 "Value of x: " (:val @x)]
- [:h2 "Value of y: " (:val @y)]
- [:h2 " Operator: " (:val @op)]
- [:h2 " Result: " (:val @result)]]]
- ]]]
- ))
- (defn render! []
- (.render js/React
- (a-simple-stateful-object x y op)
- (.getElementById js/document "app")))
- (add-watch x :on-change (fn [_ _ _ _] (render!)))
- (add-watch y :on-change (fn [_ _ _ _] (render!)))
- (add-watch op :on-change (fn [_ _ _ _] (render!)))
- (add-watch result :on-change (fn [_ _ _ _ _ _ _ _ _] (render!)))
- (render!)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement