Dimensions and updating the styles hash
(This is more of a reminder for me to investigate something)
Looking at the style method I noticed the update_dimension:
# Adds styles, or just returns current style if no argument
def style(new_styles = nil)
update_style(new_styles) if need_to_update_style?(new_styles)
update_dimensions if styles_with_dimensions?
@style
end
# dimension methods:
def update_dimensions #so that @style hash matches actual values
STYLE_GROUPS[:dimensions].each do |style|
@style[style] = self.send(style.to_s)
end
end
def styles_with_dimensions?
STYLE_GROUPS[:dimensions].any? {|dimension| @style.has_key? dimension}
end
Looks to me like whenever @style has a Dimensions key we manually update all dimension in styles to their most current version, which seems like quite the overhead to me.
Instead, I think it'd be better if the @style hash would be changed on demand whenever one of the dimension values changes.
I might be wrong, that's just my first assessment.
Agreed!
style is trying to be a central location for everything that describes an element, the only exception being the element's dimensions / position! So getting these two aspects of an element to to talk to each other nicely is really essential imo.
My question is who should be watching for the dimension or style changes? Is this a job for after_do or do we just stick methods in common/style.rb and dimensions.rb so that they each call the other when changing?
- Also, you stole my issue name! :stuck_out_tongue_closed_eyes:
I was just about to open a different issue with that exact title!
:-) Maybe we can adopt your/mine issue title then since it seems not to be specific enough. I'll give it a try.
It seems to me that this might be a nice use case for after_do to just say that after each call to these dimensions methods please do update that style hash. Thanks.