Skip to content

Instantly share code, notes, and snippets.

@dark4eg
Created July 20, 2015 12:17
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 dark4eg/7cec65e102152688d6fb to your computer and use it in GitHub Desktop.
Save dark4eg/7cec65e102152688d6fb to your computer and use it in GitHub Desktop.
(defmulti build
"Component build"
(fn [cursor owner opts]
(-> cursor :component :type)))
(defmethod build [:button] [cursor owner opts]
(reify
event-bus/IInitEventBus
(init-event-bus [_]
{:xform (add-om-id-xform owner)})
om/IWillMount
(will-mount [_])
om/IDidMount
(did-mount [_])
om/IWillReceiveProps
(will-receive-props [_ next-props])
om/IWillUnmount
(will-unmount [_])
om/IWillUpdate
(will-update [_ next-props next-state])
om/IDidUpdate
(did-update [_ prev-props prev-state])
om/IRenderState
(render-state [_ state]
(html/render (if (> (count (:view (:component cursor))) 0)
(:view (:component cursor))
[:button {:type "button"
:class "btn"}
"button"])))))
(def app-state (atom {:button {:type [:button]
:view [:button {:type "button"
:class "btn btn-default mdi-navigation-menu"
:on-click (fn [c]
(println "owner" owner))}]}}))
(om/root
(fn [cursor owner]
(om/build builder/build {:component (:button cursor}))
app-state
{:target (. js/document (getElementById "app"))
;:chsk-send! chsk-send!
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment