3 ms·
> Bootstrap 5 will remove jQuery as a dependency ... by copying over/rebuilding big chunks of it. - $(element).closest(`.${ClassName.ALERT}`)[0] + Sel
by dmitriid 8y ago
> Bootstrap 5 will remove jQuery as a dependency
... by copying over/rebuilding big chunks of it.
- $(element).closest(`.${ClassName.ALERT}`)[0]
+ SelectorEngine.closest(element, `.${ClassName.ALERT}`)
- $.Event(Event.CLOSE)
+ EventHandler.trigger(element, Event.CLOSE)
- $(element).one( ... )
+ EventHandler.one( ... )
- $(this).data(DATA_KEY)
+ Data.getData(this, DATA_KEY)
And so on and so forth.
DOM APIs are just as pain in all of parts of a dev's body as they were 10, 15, and 25 years ago. Even if you "replace" jQuery, you end up just reimplementing easily a half of it just because it's so brilliant in it's ease of use and convenience.
- tcd 8y agoYes...What were you expecting then to do? Usually you replace code if you're dropping a dependency. It's one less network request, saves bandwidth and removes obsolete and pretty much unmaintained code (at this point, the jQuery github is as good as dead, unlikely to see major releases any time soon). Seems to be a sensible approach to me. It's like using native code rather than electron, even if you add more lines, I'm pretty sure the performance gains would be worth while.
- mschuster91 8y ago> It's one less network request, saves bandwidth Given that most stuff these days is packed together with Webpack or at least concat'd together, you don't really save much, plus jQuery in gzip'd form is clocking in at <30 kB anyway (https://mathiasbynens.be/demo/jquery-size https://mathiasbynens.be/demo/jquery-size). > and pretty much unmaintained code (at this point, the jQuery github is as good as dead, unlikely to see major releases any time soon) So what? Software can very well be "done", there is no need to always evolve and evolve. As long as there is no security issue left unsolved, though. In addition, if you're rebuilding half of it on your own anyway, chances are high you'll miss some weird corner case that jQuery solved years, or decades, ago.
- tcd 8y agoI don't agree, software needs to evolve as its dependencies does. In this case we have fetch, async/await, promises and loads more native features that jQuery hasn't adapted to (XHR is obsolete now for example). Why include a dependency that the browser provides for free? jQuery was good before ES6/next came along, these days it's extra cruft. And if what you're saying is true about weird corner cases, people will fix that up in PR's anyway, that's not a reason to stop innovating and just say "meh, jQuery is good enough". Thank god most software doesn't work your way, we'd probably be stuck in the stone ages still.
- exodust 8y ago> ...promises and loads more native features that jQuery hasn't adapted to Promises work great in Jquery. I've had much success chaining combinations of AJAX and interface events together using Jquery deferred promises. Jquery is stable and reliable. Use it or don't use it. A lot of devs tend to think the whole world has an updated web browser like they do. Forgetting that millions of hand-me-down older devices that can't be updated (eg an iPad 3) will NOT load a page properly with ES6 javascript. Example: the Steam website... this site is now useless to browse on an "old" device like an iPad 3 which Apple considers "vintage" so doesn't give updates. So do we throw the iPad in the trash? We're talking an iPad 3 with retina screen and pretty good performance, but no updates to OS or web browser. In the real world, people are not throwing their iPad3's and older devices in the trash, they're keeping them around house, giving to kids or selling them on ebay, which means people are buying them on ebay and still using them for years and years.
- hombre_fatal 8y agoWell, the snippet you posted is a sensible immediate step before any dependency replacement. You replace direct usage with indirection (adapter) that still calls jQuery, ensure everything still works, then swap out the indirection's implementation (e.g. with native DOM functions), and ensure everything still works. The pattern specifically just decouples the callsite from implementation.
- tracker1 8y agoIs SelectorEngine sizzle directly? I'm not sure how practical replacing jQuery is, and not going to look that deep. But jQuery isn't nearly as big today since most browsers (even IE11) are pretty modern.
- 9dev 8y agoA good replacement selector engine: `const selectorEngine = selector => Array.from(document.querySelector(selector));` :)
- fenwick67 8y agoIt needs to be querySelectorAll, and you need to handle cases where it returns null as well.
- 9dev 8y agoDarn, that's what you get from typing on mobile. Ment to use querySelectorAll originally. But apart from null handling (which can be solved using `|| []`), what else would be lacking? I used a similar version of this for a few projects a while back, with some additional stuff for query context and ID selector -> getElementById I think, but that's basically it...
- fenwick67 8y agoIt definitely works, I've written `document.querySelectorAll(x)||[]` many times. If all you're doing is making a few simple queries, it works fine.
- drawkbox 8y agojQuery was nice in that everyone used it for a long time, it was required during browser inconsistencies and no transpiling. This made systems common for devs, and systems/skills were more transferrable without worry about browser testing hell. Now every framework will use a different internal jQuery like custom system, when these pile up high enough another jQuery like library will appear that everyone will use if browsers start fragmenting again. Though with WebAssembly and other technologies maybe less of that will be restrictive enough to need common browser baseline libraries. jQuery was very required during IE/Firefox/Chrome changes and made a baseplane of support that didn't need to be tested in every browser by every project, devs could just focus on building their webapp. It is a bit similar to a game studio making a custom engine or using a common one like Unity or Unreal, there are pros and cons of both, but the pro is the devs can focus on building a game and not having to worry as much about the engine. Now that browsers and transpilers exist, that is less of an issue but also leads to many more versions of the same thing, for better or worse. I just hope that most projects aren't bogged down in extra work and testing recreating jQuery for the thousandths time. That is one problem I see with javascript ecosystem today is that lots more work goes into the tech rather than your app/game/project/product. While it is simplifying in some areas, sometimes it can actually add complexity to your tech stack that is unnecessary and wastes cycles that should be on your product.