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
exportfunctionstyleAttr(input){consttype=typeofinput;if(type==="string"){returninput;}if(Array.isArray(input)){returninput.filter(styleAttr).join(';')}if(type==="object"){returnObject.entries(input).filter(([_,val])=>val!=null)// I’d really rather Marko 5 not do the pixel coercion below, though.map(([_,val])=>(typeofval==="number"&&val) ? `${val}px` : val).map(([name])=>DASHED_NAMES[name]||(DASHED_NAMES[name]=name.replace(/([A-Z])/g,"-$1").toLowerCase())).map(style=>style.join(':')).join(';')}}
…Well, I’m pretty sure the type === "object" codepath is not faster. But it was fun to write, and the Array.isArray codepath looks worth a benchmark.
The text was updated successfully, but these errors were encountered:
I just realized the result variable is probably because r= is more minified than return , but after dumping both into Terser:
Before (276 bytes):
function classAttrBefore(t){const r=typeof t;let n;if("string"===r)n=t;else{if(n="",Array.isArray(input))for(const t of input){const r=classAttr(t);r&&(n+=` ${r}`)}else if("object"===r)for(const t in input)input.hasOwnProperty(t)&&input[t]&&(n+=` ${t}`);n=n.slice(1)}return n}
After (173 bytes):
function classAttrAfter(t){const r=typeof t;return"string"===r?t:Array.isArray(t)?t.filter(classAttr).join(" "):"object"===r?Object.keys(t).filter(r=>t[r]).join(" "):void 0}
My proposal for styleAttr definitely minifies worse than the original, though.
[email protected]
packages/runtime/src/shared/helpers.js#L16-L20:
Some cursory research suggests that not only would
Object.keys()
be shorter, but it could be faster, too.What do you think about:
The
styleAttr
helper could be rewritten similarly:…Well, I’m pretty sure the
type === "object"
codepath is not faster. But it was fun to write, and theArray.isArray
codepath looks worth a benchmark.The text was updated successfully, but these errors were encountered: