Commit 87213bf9 authored by JC Brand's avatar JC Brand

Rename getPromiseWrapper to getResolveablePromise

Let a promise be returned instead of a wrapper, but glue the `resolve`
and `reject` methods onto it
parent 695e8f5c
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
}, },
fetchBookmarks () { fetchBookmarks () {
const deferred = utils.getWrappedPromise(); const deferred = utils.getResolveablePromise();
if (this.browserStorage.records.length > 0) { if (this.browserStorage.records.length > 0) {
this.fetch({ this.fetch({
'success': _.bind(this.onCachedBookmarksFetched, this, deferred), 'success': _.bind(this.onCachedBookmarksFetched, this, deferred),
...@@ -284,7 +284,7 @@ ...@@ -284,7 +284,7 @@
} else { } else {
deferred.resolve(); deferred.resolve();
} }
return deferred.promise; return deferred;
}, },
onCachedBookmarksFetched (deferred) { onCachedBookmarksFetched (deferred) {
......
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
/* Private function, used to add a new promise to the ones already /* Private function, used to add a new promise to the ones already
* available via the `waitUntil` api method. * available via the `waitUntil` api method.
*/ */
_converse.promises[promise] = utils.getWrappedPromise(); _converse.promises[promise] = utils.getResolveablePromise();
} }
_converse.emit = function (name) { _converse.emit = function (name) {
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
_converse.initialize = function (settings, callback) { _converse.initialize = function (settings, callback) {
"use strict"; "use strict";
settings = !_.isUndefined(settings) ? settings : {}; settings = !_.isUndefined(settings) ? settings : {};
const init_promise = utils.getWrappedPromise(); const init_promise = utils.getResolveablePromise();
_.each(PROMISES, addPromise); _.each(PROMISES, addPromise);
...@@ -611,7 +611,7 @@ ...@@ -611,7 +611,7 @@
this.initStatus = () => this.initStatus = () =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const promise = new utils.getWrappedPromise(); const promise = new utils.getResolveablePromise();
this.xmppstatus = new this.XMPPStatus(); this.xmppstatus = new this.XMPPStatus();
const id = b64_sha1(`converse.xmppstatus-${_converse.bare_jid}`); const id = b64_sha1(`converse.xmppstatus-${_converse.bare_jid}`);
this.xmppstatus.id = id; // Appears to be necessary for backbone.browserStorage this.xmppstatus.id = id; // Appears to be necessary for backbone.browserStorage
...@@ -1961,7 +1961,7 @@ ...@@ -1961,7 +1961,7 @@
_converse.log(reason, Strophe.LogLevel.ERROR); _converse.log(reason, Strophe.LogLevel.ERROR);
}); });
} }
return init_promise.promise; return init_promise;
}; };
// API methods only available to plugins // API methods only available to plugins
...@@ -2102,7 +2102,7 @@ ...@@ -2102,7 +2102,7 @@
if (_.isUndefined(promise)) { if (_.isUndefined(promise)) {
return null; return null;
} }
return promise.promise; return promise;
}, },
'send' (stanza) { 'send' (stanza) {
_converse.connection.send(stanza); _converse.connection.send(stanza);
......
...@@ -511,13 +511,17 @@ ...@@ -511,13 +511,17 @@
return model.collection && model.collection.browserStorage; return model.collection && model.collection.browserStorage;
}; };
u.getWrappedPromise = function () { u.getResolveablePromise = function () {
/* Returns a promise object on which `resolve` or `reject` can be
* called.
*/
const wrapper = {}; const wrapper = {};
wrapper.promise = new Promise((resolve, reject) => { const promise = new Promise((resolve, reject) => {
wrapper.resolve = resolve; wrapper.resolve = resolve;
wrapper.reject = reject; wrapper.reject = reject;
}) })
return wrapper; _.assign(promise, wrapper);
return promise;
}; };
u.safeSave = function (model, attributes) { u.safeSave = function (model, attributes) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment