Commit 6af02904 authored by JC Brand's avatar JC Brand

Replace $.Deferred with ES2015 promises

parent 16d62bf9
...@@ -430,8 +430,13 @@ ...@@ -430,8 +430,13 @@
'jid': 'another@conference.shakespeare.lit' 'jid': 'another@conference.shakespeare.lit'
}).c('nick').t('JC').up().up(); }).c('nick').t('JC').up().up();
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
done(); 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( it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises(
...@@ -472,15 +477,20 @@ ...@@ -472,15 +477,20 @@
'nick': '' 'nick': ''
}); });
test_utils.openControlBox().openRoomsPanel(_converse); test_utils.openControlBox().openRoomsPanel(_converse);
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED); test_utils.waitUntil(function () {
$('#chatrooms .bookmarks-toggle').click(); return $('#chatrooms dl.bookmarks dd:visible').length;
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(0); }, 300).then(function () {
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.CLOSED); expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
$('#chatrooms .bookmarks-toggle').click(); expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1); $('#chatrooms .bookmarks-toggle').click();
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED); expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(0);
done(); expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.CLOSED);
$('#chatrooms .bookmarks-toggle').click();
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
done();
});
})); }));
}); });
}); });
......
...@@ -229,8 +229,7 @@ ...@@ -229,8 +229,7 @@
}, },
fetchBookmarks () { fetchBookmarks () {
const deferred = new $.Deferred(); const deferred = utils.getWrappedPromise();
const promise = deferred.promise();
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),
...@@ -245,7 +244,7 @@ ...@@ -245,7 +244,7 @@
} else { } else {
deferred.resolve(); deferred.resolve();
} }
return promise; return deferred.promise;
}, },
onCachedBookmarksFetched (deferred) { onCachedBookmarksFetched (deferred) {
...@@ -482,7 +481,7 @@ ...@@ -482,7 +481,7 @@
return; return;
} }
_converse.bookmarks = new _converse.Bookmarks(); _converse.bookmarks = new _converse.Bookmarks();
_converse.bookmarks.fetchBookmarks().always(function () { _converse.bookmarks.fetchBookmarks().then(function () {
_converse.bookmarksview = new _converse.BookmarksView( _converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks} {'model': _converse.bookmarks}
); );
......
...@@ -69,22 +69,22 @@ ...@@ -69,22 +69,22 @@
}; };
var isImage = function (url) { var isImage = function (url) {
var deferred = new $.Deferred(); return new Promise((resolve, reject) => {
var img = new Image(); var img = new Image();
var timer = window.setTimeout(function () { var timer = window.setTimeout(function () {
deferred.reject(); reject(new Error("Could not determine whether it's an image"));
img = null; img = null;
}, 3000); }, 3000);
img.onerror = img.onabort = function () { img.onerror = img.onabort = function () {
clearTimeout(timer); clearTimeout(timer);
deferred.reject(); reject(new Error("Could not determine whether it's an image"));
}; };
img.onload = function () { img.onload = function () {
clearTimeout(timer); clearTimeout(timer);
deferred.resolve(img); resolve(img);
}; };
img.src = url; img.src = url;
return deferred.promise(); });
}; };
$.fn.hasScrollBar = function() { $.fn.hasScrollBar = function() {
......
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