Created
May 28, 2014 00:52
-
-
Save danielytics/3c51258a351b7c46f7e0 to your computer and use it in GitHub Desktop.
Clojure Om component communication example
This file contains hidden or 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
(defn child [props owner {:keys [ch]}] | |
(reify | |
om/IInitState | |
(init-state [_] | |
{:text ""}) | |
om/IRenderState | |
(render-state [_ {:keys [text editable?]}] | |
(dom/div nil | |
(if editable? | |
(dom/input ...) | |
(dom/div nil text)) | |
(dom/button #js {:onClick #(async/put! ch :no-edit)} | |
"No Edit"))))) | |
(defn parent [props owner opts] | |
(reify | |
om/IInitState | |
(init-state [_] | |
{:ch (async/chan) | |
:editable? true}) | |
om/IWillMount | |
(will-mount [_] | |
(async/go-loop [] | |
(when-let [value (async/<! (om/get-state owner :ch))] | |
(condp = value | |
:no-edit (om/set-state! owner :editable? false)) | |
(recur)))) | |
om/IRenderState | |
(render-state [_ {:keys [editable? ch]}] | |
(om/build child props {:state {:editable? editable?} | |
:opts ch})))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment