W3C home > Mailing lists > Public > www-style@w3.org > August 2013

RE: [css-om] CSSStyleDeclaration.parentElement

From: Francois REMY <francois.remy.dev@outlook.com>
Date: Sat, 24 Aug 2013 12:55:11 -0700
Message-ID: <DUB406-EAS1396081687F384EBFB59C0CA54F0@phx.gbl>
To: "'Sylvain Galineau'" <galineau@adobe.com>, "'Simon Pieters'" <simonp@opera.com>, <www-style@w3.org>
> Nonetheless, if this is really the best use
> I can make of my time, I'll try to find other 
> use cases during the weekend, we'll see
> what comes out of it.

Saturday's morning idea: 

- since getComputedStyle return a new object every time, you do not want to
call this function multiple times.
- as a result, your code contains functions where you can give a reference
to the computed style of an element in addition to the element itself (ie:
cache parameters)
- let's figure out that you made a mistake somewhere in your code and gave a
reference to the wrong style object, how do you find this out?

If you've parentElement you can do sanity checks at the beginning of your
function:

    if(elementStyle.parentElement != element) { 
        if("debug" in window) debugger; 
        elementStyle = getComputedStyle(element);
    }

The only option now would be to call getComputedStyle again and comparing
all properties in the hope you find a difference. This is so slow you
couldn't even keep that sanity check in production. Since you're calling
getComputedStyle anyway, it cancels the effect of the cache.
Received on Saturday, 24 August 2013 19:55:35 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:33 UTC