Forgot to add that Om handles mounting and unmounting when a component in a
certain place in the DOM has changed and it uses the components *function*
to determine if the component has changed (and therefore needs
unmounting/mounting). In the example, these are the widget-a and widget-b
*functions*. That means that if you wrote a function like this:

(defn my-weird-component []
  (if some-condition
    (reify ...om code here...)
    (reify ...some other om code here...)))

no matter the value of some-condition, Om will treat it as the same
component and toggling some-condition will NOT cause unmounting/mounting.
Basically, don't do this!

Practically, what this means is that multimethods won't work out of the box
because they basically turn into something like the above under the hood.
This also means you must be careful using wrapper functions around
components. Generally speaking, you should avoid doing that (or at least,
take great care).


On 26 July 2014 09:04, Daniel Kersten <[email protected]> wrote:

> https://github.com/swannodette/om/tree/master/examples/unmount
>
> The unmounting happens on lines 30 through 32:
> https://github.com/swannodette/om/blob/master/examples/unmount/src/core.cljs#L30-L32
>
>
>
> (render [_]
>
>   (dom/div nil
>
>     (if (= (:widget data) :a)
>
>
>       (om/build widget-a {})
>
>
>       (om/build widget-b {}))
>
>
>     (dom/button
>
>       #js {:onClick (fn [e] (om/transact! data :widget {:a :b :b :a}))}
>
>
>       "Switch!")))
>
>
> When the condition of the if statement changes, either widget-a or
> widget-b gets built. Consider the following flow of events:
>
> (:widget data) starts off as :a, widget-a init-state is called,
> will-mount, render, did-mount.
> User clicks the button, (:widget data) is changed to :b, widget-a
> will-unmount is called, widget-b init-state, will-mount, render, did-mount
> are called.
> User clicks the button again, (:widget data) is changed to :a, widget-b
> will-unmount is called, widget-a will-mount, render, did-mount are called.
>
> I'm ignoring the other lifecycle functions (should-update,
> will-receive-props, will-update, did-update, display-name), generally the
> will-* functions get called before render and the did-* functions get
> called after render. I'm also conflating render and render-state as they're
> basically the same thing.
>
>
>
>
> On 26 July 2014 07:46, John Chijioke <[email protected]> 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.
>>
>
>

-- 
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