Open Harbs opened 2 years ago
After thinking about this some more:
IStyleableObject
, we should add a new interface (ICSSStyleable
) which inherits from IStyleableObject
.UIBase
should implement ICSSStyleable
or there should be a subclass of that which does.ICSSStyleable
.
saveStyle
(or similar) would save a default for the class.findStyle
would get a style from the defaults walking up the inheritance if necessary. The results should be cached so the walk would only happen once per style per class.findInheritedStyle
would call find style up the parent chain until it finds a style. The parent chain results would not be cached by default. We'd need to figure out whether caching is ever a good idea.setStyle
would apply a style to an instance. In the case of HTML, this should apply the change to the element's inline css.getStyle
would get the directly applied style of the instance (if any).setStyle
and getStyle
already have defined meanings. We'd need to figure out how/if that fits with the above. mx.core.UIComponent
might need a different implementation. This might be a reason to make the implementation a subclass of UIBase
.ValuesManager.valuesImpl.getValue()
, there is no need to walk up the parent chain (such as finding default beads). For such cases simply calling findStyle()
would be enough.I'd love to hear others' thoughts on all of this.
I haven't measured specifically, but a single DOM parentNode is pretty quick (it's not an expensive traversal and doesn't modify the DOM).
I think the recursion (classes + containers) of each getStyle() call is more the issue, in general, since getStyle() is called so much.
I'd recommend modifying a version of SimpleCSSValuesImpl so that it can log all calls to getStyle so we truly understand why it is being called. If 99% is for bead lookup, then optimize bead lookup. There shouldn't be many, if any, calls to getStyle in JS. Also, the parent shouldn't be involved if the style is not inheriting.
Currently SimpleCSSValuesImpl gets style values like so:
ValuesManager.valuesImpl.init(this)
in any class which implementsIMXMLDocument
This has multiple issues:
Additonally there's some issues identified here: https://github.com/apache/royale-asjs/issues/641#issuecomment-573836029
An example of a compiled MXML lookup is this:
Here's a potential improvement:
"org.apache.royale.html.Container"
, the value can be written unquoted to refer to the class directly like we do for bead references. This will enable to compiler to minimize the references normally.valuesImpl
.IStyleableObject
setStyle()
andgetStyle()
That would put the logic of saving the style information and retrieving it in the class itself.setStyle()
andgetStyle()
would be instance methods, but it would save the information to the class so it's written once.saveCacheValue
andgetCacheValue
for optimizing lookups when walking up parents if it's known that it's safe to do so. These values would need to be saved in instances for it to work. The right balance of memory usage and speed optimization would need to be found for this.getValue
andgetInheritedValue
is called recursively ingetInheritedValue
. The current parent should probably be saved as an instance variable to prevent having to walk up the tree many times.