You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...we have to create three blocks (create_main_fragment, create_if_block and create_if_block_1), totalling 74 LOC as of the current version. If we optimised it to the equivalent of this...
<p>{foo ? 'foo!' : 'not foo!'}</p>
...we get the same result with one block (create_main_fragment) totalling 25 LOC, and there's less work to do to update things.
There are probably all sorts of optimisations like this we could perform. Might not be straightforward, but definitely worth investigating.
The text was updated successfully, but these errors were encountered:
On the if optimization, we could actually get better output than the equivalent {foo ? 'foo!' : 'not foo!'}, since the ternary ends up duplicated as-is:
functioncreate_main_fragment(component,ctx){varp,text_value=ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!',text,current;return{[...]p: functionupdate(changed,ctx){if((changed.foo)&&text_value!==(text_value=ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!')){setData(text,text_value);}}[...]};}
Yeah, that's unfortunate. I've wondered about having block-level helpers like
functioncreate_main_fragment(component,ctx){varp,get_text=ctx=>ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!',text_value=get_text(ctx),text,current;return{// ...p(changed,ctx){if(changed.foo&&(text_value!==get_text(ctx)){setData(text,text_value);}}};}
In fact those could be hoisted, and potentially even deduplicated across a bundle:
constget_text=ctx=>ctx.foo ? 'Some large static string...' : 'Or an even bigger one here!';functioncreate_main_fragment(component,ctx){varp,text_value=get_text(ctx),text,current;return{// ...p(changed,ctx){if(changed.foo&&(text_value!==get_text(ctx)){setData(text,text_value);}}};}
Second random thought after #645. In cases like this...
...we have to create three blocks (
create_main_fragment
,create_if_block
andcreate_if_block_1
), totalling 74 LOC as of the current version. If we optimised it to the equivalent of this......we get the same result with one block (
create_main_fragment
) totalling 25 LOC, and there's less work to do to update things.There are probably all sorts of optimisations like this we could perform. Might not be straightforward, but definitely worth investigating.
The text was updated successfully, but these errors were encountered: