Created
December 31, 2013 02:47
-
-
Save haywoood/8191733 to your computer and use it in GitHub Desktop.
simple om
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 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