Skip to content

Instantly share code, notes, and snippets.

@haywoood
Created December 31, 2013 02:47
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 haywoood/8191733 to your computer and use it in GitHub Desktop.
Save haywoood/8191733 to your computer and use it in GitHub Desktop.
simple om
(ns examples.hello.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(defn handle-change [e data]
(let [val (.. e -target -value)]
(println val)
(if (= 13 (.-keyCode e))
(om/update! data conj {:input-val "" :text val})
(om/update! data conj {:text val :input-val val}))))
(defn reset-input [data]
(om/update data conj {:input-val ""}))
(defn widget [data]
(.log js/console (om/read data :input-val))
(om/component
(dom/div nil
(dom/div nil (:text data))
(dom/input
#js {:onKeyUp #(handle-change % data)
:value (:input-val cursor)}))))
(om/root {:text "Hello World!" :input-val ""} widget (.getElementById js/document "app"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment