Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is jQuery an Ember.js dependency?

Tags:

ember.js

I can understand needing some abstraction layer for common operations like retrieving DOM elements, attribute manipulation, etc., but jQuery is a pretty massive library that seems like a lot of overkill for Ember.

After looking through the source code, there are only about 30 or so uses of jQuery in Ember and it looks like the majority of jQuery usage is simple selector calls, some events, and some DOM traversal.

Ember.$(rootElement).off('.ember', '**').removeClass('ember-application');

...

elem = this.$();

...

this.$().appendTo(target);

...

Ember.$(window).on('hashchange.ember-location-'+guid, function() {

etc.

Are there any other reasons Ember requires jQuery for every application?

Could these few uses be embedded into Ember and jQuery removed as a dependency?

like image 815
Jonathan Dumaine Avatar asked May 22 '13 23:05

Jonathan Dumaine


People also ask

Does Ember use jQuery?

Ember has been historically coupled to jQuery. As part of RFC294, jQuery has been made optional. This addon makes jQuery available in an Ember project. It also provides the mechanism that implements jQuery integration when that feature is enabled.

What is the use of Ember js?

js is an open-source JavaScript web framework that utilizes a component-service pattern. It allows developers to create scalable single-page web applications by incorporating common idioms, best practices, and patterns from other single-page-app ecosystem patterns into the framework.

Why use jQuery?

The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.


2 Answers

The question was extremely well explained by Tom Dale (Ember Core Developer).

Essentially he says:

Ember.js requires jQuery for two reasons:

  • We rely on it heavily in the Ember/Handlebars integration for inserting and modifying DOM elements. I personally am not interested in dealing with cross-browser DOM manipulation bugs, but the jQuery team excels at it.
  • By having a standard DOM manipulation library in jQuery, developers can move between different Ember.js apps and rely on the fact that they have a battle-tested, cross-platform library underneath them.

If you are concerned about size, I'd recommend investigating the new jQuery 2.0, which has the ability to do custom builds without features such as animation.

Makes a lot of sense to me.

Update:

Recently Erik Bryn (Ember Core Developer too) wrote a very interesting comment about the framework and mentioned the state of the art of jQuery usage in Ember projects.

Pasting the comment:

It's a common misconception that Ember.js is monolithic. I can assure you that isn't actually true. You can pick and choose the parts of Ember that you want or need (for example, the router is totally optional). Our build tools even support picking and choosing which packages you want. You can use it today without jQuery (you will need to shim and have an event delegation library, or even easier use a super-lightweight custom jQuery build).

like image 172
Javier Cadiz Avatar answered Oct 12 '22 10:10

Javier Cadiz


Only Ember's view layer depends on jQuery. It was used more heavily historically than it is now. In the future, we could as you suggest, roll functionality into Ember itself, although we do not want to maintain cross-browser compatibility in Ember that jQuery is already taking care of. Another path, with jQuery 2.0, would be a way to create trimmer build of jQuery containing just the portions that Ember uses.

If there are no-compromise ways to replace instances of jQuery usage in Ember core, you should propose the changes as issues on GitHub.

like image 24
Luke Melia Avatar answered Oct 12 '22 09:10

Luke Melia