Hi John,

Unmounting is not something that you do explicitly; it happens
automatically when the data that maps to a component is no longer
present, or if you conditionally disable building of a child component.

For example, if you build a child component based on the value of a
component local state value (I'm using sablono/hiccup syntax in examples
to be concise--let me know if anything is not clear):

;; In render phase of parent
(if (om/get-state owner :show-child-component?)
  (om/build child-component app-data ...)
  [:div.hidden "Don't show child."])

That will mount and unmount the child-component based on the status of
the :show-child-component? value.

Similarly, if you have a collection of child component items in a parent
component, and that collection will change during the lifecycle of the
parent, those individual items' components will be mounted and unmounted
as necessary:

;;
;; List could be something like:
;; [{:name "item1" :id 1} {:name "item2" :id 2}...{:name "itemN" :id N}]
;;

;; in parent component render phase:
;; ...
[:ul
(om/build-all list-element list-items {:key :id})]
;; ...

;; In each child component:
(defn child
  [{:keys [id name] :as list-item} owner]
  (reify
    om/IWillUnmount
    (will-unmount [_]
      ;; Here do cleanup and whatnot before unmounting.
      ;;
      ;; If I call something like
      ;;  (om/transact! app-data #(remove-item-at n))
      ;; (in the *parent*, not here), this will get called.
      ;;
      (println "Unmounting item " id))

    om/IRenderState
    (render-state [_ state]
      (html ; sablono
        [:li {:data-id id} name]))))

I hope this helps, let me know if anything is unclear.

DD

(2014/07/26 15:46), John Chijioke wrote:
> Please is there a valid example somewhere that illustrates unmounting an om 
> component from the DOM?
> 

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to