Hi,
I'm struggling with property observation in elements with properties that depend on each other. I keep running into infinite loops but I feel like this should be easy to fix.
Suppose I have a <color-picker> element with six properties: red, green, blue, hue, saturation, lightness. I'd like to be able to set any one of these properties, and have the other properties automatically update. For example, if I set one or more of the RGB properties, the equivalent HSL properties should update. And vice versa.
I have two observers:
* 'rgbChanged(red, green, blue)', which sets the HSL based on the new RGB
* 'hslChanged(hue, saturation, lightness)', which sets the RGB based on the new HSL
The problem is that changing one set of values will cause the other set of values to be changed, causing the other observer to also be called.
Best case scenario: wasteful calculation. if I set RGB, rgbChanged calculates HSL, then hslChanged calculates RGB. This is redundant; these RGB values should be the same as the RGB I set originally.
Worst case scenario: the two functions aren't perfectly symmetrical, due to rounding error. Now the observers will trigger each other until I reach the stack size limit.
In a non-Polymer world, I would probably handle this by adding a "isUpdating" flag, and clear the flag in a setTimeout after changing properties. Is there a Polymeric way of handling this?
Thanks.
Michael