@mattmcmanus wrote:
Hey Folks, I’m trying to wrap my brain around some of the autotracking changes in Octane and having a hard time. Does autotracking work on a Set?
I want to calculate the height of a list of elements and I figured a Set would make the unique tracking easy. Take a look at the code below. I have a Set of dom elements, which is tracked. The
height()
method isn’t being called again when theelements
changes.@tracked elements = new Set(); get height() { if (this.elements.size === 0) { return 'auto'; } let height = [...this.elements].reduce((sum, el) => sum + el.offsetHeight); return `${height}px`; } @action addEl(el) { this.elements.add(el); } @action removeEl(el) { this.elements.delete(el); }
Then I’m referencing
height
in a template:<div style="flex-basis: {{this.height}}" > ...
This is my first attempt at using a Set as well, so it’s possible I’m heading down the wrong path before the autotracking confusion. I’ve tried this with
elements
as an array andheight
is still not called.Thanks for the help!
Posts: 4
Participants: 2