Created
February 21, 2015 13:02
-
-
Save bonega/436f1d7a65a5270952f2 to your computer and use it in GitHub Desktop.
Example rum
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 rumming.core | |
(:require [rum])) | |
(defn handle-number-input [event owner] | |
(let [text (.. event -target -value) | |
num-pattern #"-?\d*"] | |
(if (re-matches num-pattern text) | |
(reset! owner text) | |
(reset! owner @owner)))) | |
(rum/defc input < rum/reactive [ref] | |
[:input {:type "text" | |
:value (rum/react ref) | |
:style {:width 100} | |
:on-change #(handle-number-input % ref)}]) | |
(def app-state (atom {:first-input "123" :second-input "456"})) | |
(rum/defc big-component < rum/cursored-watch [app-state] | |
[:div | |
(input (rum/cursor app-state [:first-input])) | |
(input (rum/cursor app-state [:second-input]))]) | |
(defn main | |
[] | |
(rum/mount (big-component app-state) (.-body js/document))) | |
(set! (.-onload js/window) main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment