Get rid of jQuery in UI5
2023-11-6 17:44:4 Author: blogs.sap.com(查看原文) 阅读量:8 收藏

jQuery has been the most used JavaScript framework ever created. It took web development out of the Dark Ages and brought some joy to web developers (no more fiddling with browser agents and conditional code). However, jQuery is not required in modern js apps anymore. As JS and CSS evolved, and the world moved away from Internet Explorer (hallelujah!!!), jQuery has become outdated and old-fashioned. OpenJS Foundation has updated the jQuery UI and jQuery Mobile projects to “Emeritus” which means they’ve reached their lifecycle and are retired.

jQuery%20joke

jQuery joke

Somehow, UI5 is the only active modern JS framework still using jQuery. Nobody likes it any longer. It bloats the UI5 framework and brings no real value anymore. Now, with the latest UI5 long-term maintenance v120 released, it seems we’re entering a new era!

If your pastime is reading CHANGELOGs, you may’ve noticed that heaps of APIs have been deprecated and a lot of jQuery code has been replaced by native vanilla JS! I have no idea when SAP will get rid of jQuery for real, but I believe it won’t take long (in SAP time it might be a decade or so 😜). It’s about time to get rid of it!

That said, I think we, as a community, could help with that. I’ve been contributing to UI5 for a long time, and I love replacing jQuery stuff with vanilla JS! I’ve created a new git branch with some ESLint rules, eslint-plugin-no-jquery, to find jQuery in UI5 codebase. This makes finding and replacing jQuery much easier.

Git clone my fork, and checkout the no-jquery branch. Then, install the dependencies and run ESLint with the no-jquery rules!

git clone https://github.com/mauriciolauffer/openui5.git
git checkout no-jquery
npm ci
npm run lint:jquery

If you want to focus on a specific issue only, remove all the rules you do not want from the file .eslintrc-nojquery.json and leave just the rule you want to work on.

{
	"root": true,
	"env": {
		"browser": true,
		"es2022": true,
		"jquery": false
	},
	"globals": {
		"sap": true,
		"jQuery": false
	},
	"plugins": [
		"no-jquery"
	],
	"extends": ["plugin:no-jquery/all"],
	"rules": {
		"no-jquery/no-closest": "error"
	}
}

no-jquery%20results

no-jquery results

Join me on this herculean task 🥲

You may learn a trick or two during the hunt, and I’m sure you’ll understand UI5 even more. Perhaps SAP feel sorry for us and speed up the process, then we can finally have a nice and clean UI5 codebase.

Follow some links that will help you on replacing jQuery by vanilla JS alternatives:


文章来源: https://blogs.sap.com/2023/11/06/get-rid-of-jquery-in-ui5/
如有侵权请联系:admin#unsafe.sh