Reputation: 7082
I am working on a Chrome extension which has no reason to use jQuery, but which does have a reason to use the meteor-ddp.js script, which uses jQuery only in order to access the $.Deferred
functionality. It only uses three methods: reject
, resolve
and promise
:
var conn = new $.Deferred();
//...
conn.reject(err);
//...
conn.resolve(data);
//...
return conn.promise();
Now that JavaScript has its own native Promise objects, it seems unnecessary to include at least 69 KB of jQuery slim.min.js just to provide a promise feature.
It would be great if someone with more experience than I have of jQuery and promises could explain how the $.Deferred
functionality works, and how it could be replaced with native Promises.
Upvotes: 5
Views: 2283
Reputation: 1722
This would be the equivalent of your code sample in es6:
return new Promise((resolve, reject) => {
// ...
reject(err);
// ...
resolve(data);
});
Upvotes: 8