Closed kahlin closed 10 years ago
I recently hit the opposite scenario: where components were being mounted/unmounted when I wasn't expecting them to. What I learned is that build
checks if the component function has changed to determine if the component needs to be mounted or not. Basically it does something like is if (= cached-component new-component)
then simply render, otherwise unmount cached-component, mount new-component and render new-component.
Because you are using a multimethod, even though the widget changes, the function remains the same, so Om thinks its still the same component and does not unmount it. This is because the multimethod dispatch function actually does remain the same - its just where it dispatches to that changes.
This is a known limitation, a component is identified by its function. If you are going to use multimethods you need to return the top level function that will actually construct the component.
I will amend the documentation for build to make note of this.
I figured it had something to do with the function not changing but wasn't sure how to get around it. Thanks!
I modified the unmount example to use multimethods:
Now, IWillUnmount is never called. That seems to go for IWillMount as well, except IWillMount is called once when the page is loaded and widget A is rendered and never after that.