- 🇫🇷France nod_ Lille
Since this is picking up again, going to post some more guidelines.
Remove where possible, do not copy jQuery source
We are not going to copy the source code of jQuery or implement a similar function into Drupal if it can't be done natively. It might be an option in the future but we're not there yet. If replacing a method means rewriting a part of jQuery or adding a global "utility" function, it is not worth it at this time. jQuery isn't broken and we can always try to use a custom built version of jQuery
If the replacement is hard to read
It's a little subjective but when the vanilla JS is getting too much in the way of understanding the code, it's not worth it. We either need to wait for browsers to be better or re-architect the script instead of trying to replace small pieces of it.
- 🇺🇸United States smustgrave
Closed 📌 Refactor (if feasible) uses of the jQuery wrap functions to use vanillaJS Closed: won't fix as won't fix. Moving credit from that ticket to here.
Do wonder what others thoughts are on
$('.ui-dialog-off-canvas')
to$('.ui-dialog-off-canvas')[0]
To me that reads worse but will defer to the community, there are a number of issues in review like that.
- 🇺🇸United States pcate
Do wonder what others thoughts are on
$('.ui-dialog-off-canvas') to $('.ui-dialog-off-canvas')[0]
To me that reads worse but will defer to the community, there are a number of issues in review like that.An alternative would be using the .first method:
$('.ui-dialog-off-canvas').first()
or using array destructuring:const [dialog] = $('.ui-dialog-off-canvas')
- 🇺🇸United States smustgrave
The array destructuring looks a little better to me. but will lean on javascript and frontend people to decide that. About 7-8 tickets in review that contain a change like that
- 🇫🇷France nod_ Lille
I'm going to try and refocus the jQuery removal work and to do that I need to take a few decisions. I'm going to close a few issues that are most likely to introduce regressions and concentrate on the bigger topics.
The issues I'll be closing risk introducing problems with contrib and/or introduce too much extra code that looks similar to jQuery. jQuery can be handy, even elegant in some cases and the replacement will be harder to maintain.
I'm porting credit from closed issues to 📌 Credit for work on the reduce jQuery issues Active because some of those issues have significant work behind them