Did you do any profiling?

If it’s quick and efficient to remove the rule, I’d do it. If it’s expensive, 
it’s likely better to leave it. It would take a lot of lookups to make a 
measurable difference in performance.

I’d actually make an optimization there: It looks like it’s adding a class rule 
for **every** instance added. It would be much better to create one rule for 
each size, so if you have 100 instances that are all the same size, there would 
only be a single lookup.

If you do that, you’re definitely better off leaving the rule.

Thanks,
Harbs

> On Jul 28, 2024, at 2:08 AM, Maria Jose Esteve <mjest...@iest.com> wrote:
> 
> I wanted to ask for your opinion on an improvement I wanted to push.
> The Jewel InputButtonSize bead creates a custom selector (its name is a time 
> token) and adds it to the "royale_dynamic_css" sheet, with 
> addDynamicSelector, and then assigns it to strand replacing the "className" 
> property which overrides any previous value that was indicated in this 
> property.
> To override this behavior I have used "removeClass" and "addClass" but I have 
> a question... is it worth removing the selectors that have been created and 
> become unused? (I have created the "removeDynamicSelector" class)
> 
> This is the current code block of the bead:
> 
>                               /**
>                               * @private
>                               * @royaleignorecoercion 
> org.apache.royale.jewel.CheckBox
>                               */
>                               COMPILE::JS
>                               private function 
> sizeChangeHandler(event:Event):void
>                               {
>                                               var ruleName:String;
>                                               var beforeSelector:String = "";
>                                               if(width || height) {
>                                                               ruleName = 
> "inpbtn" + ((new Date()).getTime() + "-" + Math.floor(Math.random()*1000));
>                                                               (host as 
> StyledUIBase).className = ruleName;
>                                               }
> 
> And this is the same block with my modifications:
> 
>                               private var ruleName:String = "";
>                               /**
>                               * @private
>                               * @royaleignorecoercion 
> org.apache.royale.jewel.CheckBox
>                               */
>                               COMPILE::JS
>                               private function 
> sizeChangeHandler(event:Event):void
>                               {
>                                               var beforeSelector:String = "";
>                                               if(width || height) {
>                                                               if(ruleName!="")
>                                                               {
>                                                                               
> removeDynamicSelector(".jewel." + ruleName + " input+span::before");
>                                                                               
> removeDynamicSelector(".jewel." + ruleName + " input+span::after");
>                                                                               
> if ((host as StyledUIBase).containsClass(ruleName) )
>                                                                               
>                (host as StyledUIBase).removeClass(ruleName);
>                                                               }
>                                                               ruleName = 
> "inpbtn" + ((new Date()).getTime() + "-" + Math.floor(Math.random()*1000));
>                                                               // (host as 
> StyledUIBase).className = ruleName;
>                                                               (host as 
> StyledUIBase).addClass(ruleName);
>                                               }
> Thx.
> Hiedra
> 

Reply via email to