What is the general method to approach notifying a parent component of style changes in an element which is in a child component?
In my app we have a few components. The relevant ones are,
-
RootContainer
- Is what it’s named, a container from which we manipulate all the rest of the child/sibling components in our app.
-
LoadingPage
-
This component displays a gif which is an animation of the company logo and then hides itself, after 2.5 seconds (when the gif ends) by setting the display style to none of
loading-page-container
usingsetTimeout
inhide_handler
. Just to be clearLoadingPage.hbs
looks like:<div id="loading-page-container"{{did-insert this.hide_handler}}> <div id="loading-page-animoji-container"> <picture id="loading-page-animoji"> <source srcset="assets/images/loading-page-animoji-large.gif" media="(min-width:768px)"> <source srcset="assets/images/loading-page-animoji-small.gif" media="(min-width: 320px)"> <img src="assets/images/loading-page-animoji-small.gif" alt="PROBLEM"> </picture> </div> </div>
-
-
NavigationBar
- Contains Links For home, about, contact us etc.
The structure of RootContainer.hbs
is :
<div id="root-container">
<LoadingPage @timeout=3000 />
<NavigationBar />
<Component1 />
<Component2 />
.
.
.
</div>
I’d like to render NavigationBar
only after the LoadingPage
hides itself. With something along the lines of:
<div id="root-container">
<LoadingPage @timeout=3000 />
{{#if LoadingPageIsHidden }}
<NavigationBar />
<Component1 />
<Component2 />
.
.
.
{{/if}}
</div>
-
Since we hide
LoadingPage
by setting the display style to none ofloading-page-container
, I thought I could use aMutationObserver
similar to This because there isn’t really event handling for changes in element attributes. -
I thought about using tracked variables but they only seem to work in conjuction with an event processed by an action.
-
Alternatively could this problem be solved by using ember models? From what I understand templates are notified of changes to the model without me setting up observers/(event _handlers + listeners)
Sorry this was a bit long-winded suffice it to say, how would you implement LoadingPageIsHidden
?