Skip to content

Instantly share code, notes, and snippets.

@bonega
Created February 21, 2015 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonega/436f1d7a65a5270952f2 to your computer and use it in GitHub Desktop.
Save bonega/436f1d7a65a5270952f2 to your computer and use it in GitHub Desktop.
Example rum
(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