How to solely upgrade an element and all its children - material-design-lite

Using componentHandler.upgradeAllRegistered(); upgrades all matching elements within the DOM, which is an unnecessary performance cost in my case:
When I insert an element in the DOM, anything from parent to root does not need to be re-upgraded. Only the element and its children are newly created elements and need re-initialization.
How can I achieve this functionality?
Some insides: https://github.com/google/material-design-lite/issues/871

componentHandler.upgradeElements(node)
Where the node variable is the element (and children) you wish to upgrade.

Related

Angular2 Nested Visibility

I am implementing a recursive component that displays tabs and uses visibility to show only the active content. I choose this approach because the tab contents are expensive to generate and to layout from a DOM perspective.
based on this, i see that when i hide a tab, the nested child tabs are still visible.
I am thinking that the best way to handle this is by creating a set of css classes:
p-visible
p-visible-hidden
This way, I can recurse through the DOM elements when a tab is set to hidden and change any elements having a p-visible class to having the p-visible-hidden class instead. Similarly, when a tab is set to visible, i can switch all of the elements that have the p-visible-hidden class to p-visible.
So I'm wondering the best way to implement this in Angular2 - To me, the best way maybe to actually select the child DOM elements.
Thanks in advance for any help :)
test harness for component
tab layout component
I was able to solve the problem by creating an #Input boolean (called parentVisible) that indicates if the parent is visible or hidden. This property is cascaded down through the recursive hierarchy of components.
The parentVisible boolean is an additional filter on setting each child element's visibility (if parentVisible is false, the visibility is set to hidden, if parentVisible is true, then set the visiblity as before)
This strategy makes it possible to avoid direct DOM manipulation which is deemed good for unit testing and doing things in the Angular2 way :smile:

What is involved in Chrome's Recalculate Style Event?

TL;DR
What causes Recalculate Style in Chrome and what could be done to reduce the time for this step?
Background
In an application with many elements (variable, e.g. 10,000) I observe Recalculate Style taking a long time when adding a class on the parent element of those elements. There are selectors that will affect elements of each subtree when the container has this class.
In the developer tools I was able to trace the cause of the Recalculate Style event by clicking here (screenshot of a MCVE):
From to the name I assume that this step involves calculating the effective (final) element style. I think this happens when
a changed element style,
a changed (pseudo-) class
of the element itself or
of a parent or sibling element that is related by a selector or
a changed CSS selector (importing new CSS, generating <style>)
forces the browser to recalculate the CSS attributes of an element.
Attempt to prove my thesis
I created a MCVE with the same amount of elements as static HTML and toggling a class .change on a .container using a click handler on the document - dead simple code.
The MCVE performs much better than the actual application, the step Recalculate Style takes less time. This is probably due to the simpler tree and less styles.
Then I started adding more styles to all selectors and the average time increased with every bunch of new CSS attributes. Adding more elements to the 10,000 subtrees did not change the average time.
So, I'd say that the amount of CSS attributes, the count of selectors affected and the count of elements affected influences this time.
Recalculate Style
Get all the style rules
Evaluate the selectors and match against the DOM
Calculate the computed style for every element
Basically anytime you change a classname or other operations like that.
References
https://youtu.be/0xx_dkv9DEY?t=204
https://developers.google.com/web/fundamentals/performance/rendering/reduce-the-scope-and-complexity-of-style-calculations

Parent LenZ is not a sum of Children LenZ?

Alright, i'm creating a Sketchup model but i'm confused. The parent component is not taking it's children properties correctly. Is this normal?
Never mind. I fixed it! In case other people stumble on this problem: In every child component add the attribute you want to let the parent to Sum up.. (in my case i forgot to add the attribute "LenZ" to a component at the bottom of the list). If you do not add them the parent will not sum them.

Flex 3: Possible to call child function from within parent?

Is it possible to call a child function from within the parent? I know to go child > parent, you can do parentApplication.functionName(parameters);, but what about going the other way... that is parent > child?
Yes, a component should have specific references to it's children:
myChild.function(functionArguments);
The function needs to public, though. I don't recommend calling methods in the parent from the child, though. That is a break of encapsulation.
Ever heard of using an id? or a data structure to store the child?
Also, it should be noted that doing parentApplication.functionName is a very bad coding practice.

flex 4: does remove element also destroys the element?

I dynamically add and remove elements form VGroups. When I create an element and then append it to a VGroup and then remove it from that VGroup, does it destroy the element completely? if not, how can I destroy the element so it won't take space in memory.
An Object is sent to the garbage collector as long as there are no references to this object. which means two things:
all container elements that include this object should remove the element (Group,Box,Container,...)
all event listeners should be removed.

Resources