-
Notifications
You must be signed in to change notification settings - Fork 234
Removing jQuery dependency for Bloodhound #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Update
As far as I can tell, the code is now compatible again with IE8 and up. |
|
any idea when this will be merged? |
|
Any @corejavascript/collaborators have time to review this? I've changed employers and no longer use this project on a daily basis, so I can't justify taking on-the-clock time for maintenance like I used to. |
|
@jslegers Nice work. One question: why doesn't this PR remove jquery from package.json? |
|
@mhluska :
Thanks!
After my refactoring, Bloodhound no longer has jQuery as a dependency. However, Typeahead still does. So, if you can to use Bloodhound without Typeahead, you no longer need jQuery. If you want to use Typeahead, you'll still need jQuery... for the time being. If I had more time... |
|
@jslegers is there any chance to publish this as a standalone NPM package? I would love to use this in my project without committing the dist.min.js file to my repo (and without having jquery in my dependency tree). I'm imagining just bloodhound-without-jquery as an NPM package. |
|
If I ever get some time for it, I sure would consider giving it a try. In the meantime, @ anyone reading this : feel free to fork my fork and create your own standalone Bloodhound repo based on it. |
|
Damn I wish we could implement this sooner rather than later. Perhaps leverage axios to handle the requests.. |
|
@jslegers is there a reason why you didn't removed jQuery from typeahead? or was it simply lack of time? |
There's several reasons I only removed jQuery from Bloodhound and not from Typeahead :
|
I removed jQuery as a dependency for Bloodhound.
Implementation details
$.error(s)withnew Error(s)$.deferredwithsimply-deferred, which introduces aDeferredobject that has an API that's compatible with$.deferred$.ajaxwith a custom implementation that partially implements the API of$.ajaxand returns aDeferredobject$.extend,$.noop,$.paramand a few other methods with equivalent methods incommon/utilsthat have the same API and the same behavior (at least in the contexts required by Bloodhound & Typeahead) but don't use jQuery as a dependencycommon/utilsthat used jQuery as a dependency with equivalent methods that have the same API and the same behavior but don't use jQuery as a dependencyCaveats
$.ajaxinstead of_.ajaxbecause ajax mocking in unit tests relies onjasmine-ajaxv1.3.1, which only supports Ajax calls that use jQuery.Notes
The filesize of
bloodhound.jsincreased from 33.8 KB to 52 KB and the filesize ofbloodhound.min.jsincreased from 13.3 KB to 18.8 KB, as a consequence of replacing$.deferred,$.ajax,$.noop,$.paramand other methods with equivalent implementations that don't rely on jQuery. However, there may still be some baby fat in these methods that could be trimmed (for example, unnecessary method & properties could be removed fromDeferred). Nevertheless, for the time being I believe adding 5KB tobloodhound.min.jsis a sacrifice worth being able to use Bloodhound without jQuery in all supported browsers.I would recommend replacing
Deferredwith an implementation based on the nativePromiseobject at some point in the future, but I don't think it's a good idea to do this as long as you plan on supporting any version of IE, since IE is lacking nativePromisesupport and you'd need a polyfill anyway. So, at the moment, I don't believe replacingDeferredwith a Promises/A+ compliant implementation is really worth the effort.