Open oallouch opened 9 years ago
@oallouch nice input! We will be dropping some old browsers soon and that will make possible some nice refactoring. If you want to take part on that would be great. I can ping you here.
I don't have plenty of time (3 parallel projects), but always for mootools !
camelCase
is breaking, :-1: - code in the wild references properties in the stupidest way possible, mix of scripting, CSS styles, prefixes etc. although I agree this is going to help, it will break people's apps. perhaps can be protected by compat mode.String(300.5)
would turn to 301, not sure why is is being done--somebody would know. arguably again, if you pass 300.5px
, you will hit the fastest code path where it does not have to do anything once it determines it's a string that does not coerce to number and will just set the style property. Element.Styles
could use arrays indeed, and that will help - but it's going to break stuff again due to a lot of code that adds to the styles collection for custom property parsing, animating transitions and CSS3 props mootools does not 'know about'. Right now you can add custom parsers by simply doing Element.Styles.textShadow = '@px @px @px @'; document.getElement('.foo').setStyle('text-shadow', [2, 2, 2, 'red']);
- in the new syntax, this would be more like ['@px', '@px', '@px', '@']
which is slightly awkward - Array.from(value)
is a little defensive and can probably go. caching and pre-emptive split is not an option that will work very well due to late adding of element styles. your gain will be lost by looking to see if the cache is populated or splitting afresh after... to be honest you don't need to maintain your own version of mootools for this - just add Element.prototype.css = function(key, value) { .. your faster one }
and use it like jQuery. If you change styles all the time you are probably animating - and if performance is your concern, look at velocity.js
as it is cleaner and perf-centric style changes / tweens
It's the camelCase that hurts most, but, you're right, it comes from an age when we didn't have css animations. Thx for the velocity tip. Looks great.
Hi everyone, In modern web (or mobile) applications, setStyle can be called millions of times. It's, for me, the most crucial code for good lower level performance. So, optimization ideas for the Element.setStyle function: . remove the camelCase(). I've already done it in my version. Try it ! It's great :) . remove the Math.round around 'val'. With retina screens, sub-pixels become real pixels . (Element.Styles[property] || '@').split(' ') should be cached. Instead of Strings, Element.Styles values should be Arrays . if the split array has a length of 1, we don't have to do a "Array.from(value)"
What do you think of it ?
Thx,
Olivier Allouch http://www.illicotravel.com