Skip to content

Instantly share code, notes, and snippets.

@danielytics
Created May 28, 2014 00:52
Show Gist options
  • Save danielytics/3c51258a351b7c46f7e0 to your computer and use it in GitHub Desktop.
Save danielytics/3c51258a351b7c46f7e0 to your computer and use it in GitHub Desktop.
Clojure Om component communication example
(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