Replace $.Deferred with ES2015 promises

This commit is contained in:
JC Brand 2017-07-11 17:21:13 +02:00
parent 16d62bf9e4
commit 6af029048d
3 changed files with 40 additions and 31 deletions

View File

@ -430,8 +430,13 @@
'jid': 'another@conference.shakespeare.lit'
}).c('nick').t('JC').up().up();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
test_utils.waitUntil(function () {
return $('#chatrooms dl.bookmarks dd').length;
}, 300).then(function () {
expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
done();
});
}));
it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises(
@ -472,6 +477,10 @@
'nick': ''
});
test_utils.openControlBox().openRoomsPanel(_converse);
test_utils.waitUntil(function () {
return $('#chatrooms dl.bookmarks dd:visible').length;
}, 300).then(function () {
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
$('#chatrooms .bookmarks-toggle').click();
@ -481,6 +490,7 @@
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
done();
});
}));
});
});

View File

@ -229,8 +229,7 @@
},
fetchBookmarks () {
const deferred = new $.Deferred();
const promise = deferred.promise();
const deferred = utils.getWrappedPromise();
if (this.browserStorage.records.length > 0) {
this.fetch({
'success': _.bind(this.onCachedBookmarksFetched, this, deferred),
@ -245,7 +244,7 @@
} else {
deferred.resolve();
}
return promise;
return deferred.promise;
},
onCachedBookmarksFetched (deferred) {
@ -482,7 +481,7 @@
return;
}
_converse.bookmarks = new _converse.Bookmarks();
_converse.bookmarks.fetchBookmarks().always(function () {
_converse.bookmarks.fetchBookmarks().then(function () {
_converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks}
);

View File

@ -69,22 +69,22 @@
};
var isImage = function (url) {
var deferred = new $.Deferred();
return new Promise((resolve, reject) => {
var img = new Image();
var timer = window.setTimeout(function () {
deferred.reject();
reject(new Error("Could not determine whether it's an image"));
img = null;
}, 3000);
img.onerror = img.onabort = function () {
clearTimeout(timer);
deferred.reject();
reject(new Error("Could not determine whether it's an image"));
};
img.onload = function () {
clearTimeout(timer);
deferred.resolve(img);
resolve(img);
};
img.src = url;
return deferred.promise();
});
};
$.fn.hasScrollBar = function() {