[extensions-web] Migrate from jQuery.Deferred to Promise
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Migrate from jQuery.Deferred to Promise
- Date: Sat, 3 Dec 2016 09:11:08 +0000 (UTC)
commit e42c34064528a0710be29427ffed9d4661a26973
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Sat Dec 3 12:05:52 2016 +0300
Migrate from jQuery.Deferred to Promise
sweettooth/static/js/extensions.js | 18 +++++++++---------
sweettooth/static/js/versions/common/common.js | 14 ++++++--------
2 files changed, 15 insertions(+), 17 deletions(-)
---
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index c136c56..6017bc1 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -73,7 +73,7 @@ function($, messages, dbusProxy, extensionUtils, templates) {
dbusProxy.extensionStateChangedHandler = extensionStateChanged;
dbusProxy.shellRestartHandler = function() {
- dbusProxy.ListExtensions().done(function(extensions) {
+ dbusProxy.ListExtensions().then(function(extensions) {
$.each(extensions, function() {
extensionStateChanged(this.uuid, this.state);
});
@@ -94,13 +94,13 @@ function($, messages, dbusProxy, extensionUtils, templates) {
$elem.find('.upgrade-button').on('click', function() {
$elem.removeClass('upgradable');
- dbusProxy.UninstallExtension(uuid).done(function(result) {
+ dbusProxy.UninstallExtension(uuid).then(function(result) {
// If we weren't able to uninstall the extension, don't
// do anything more.
if (!result)
return;
- dbusProxy.InstallExtension(uuid).done(function(result) {
+ dbusProxy.InstallExtension(uuid).then(function(result) {
if (result === 'cancelled') {
// WELP. We can't really do anything except leave the
// thing uninstalled.
@@ -135,7 +135,7 @@ function($, messages, dbusProxy, extensionUtils, templates) {
if (oldState == ExtensionState.UNINSTALLED) {
// If the extension is uninstalled and we
// flick the switch on, install.
- dbusProxy.InstallExtension(uuid).done(function(result) {
+ dbusProxy.InstallExtension(uuid).then(function(result) {
if (result === 'succeeded') {
sendPopularity('enable');
} else if (result === 'cancelled') {
@@ -183,7 +183,7 @@ function($, messages, dbusProxy, extensionUtils, templates) {
$.fn.addLocalExtensions = function () {
return this.each(function() {
var $container = $(this);
- dbusProxy.ListExtensions().done(function(extensions) {
+ dbusProxy.ListExtensions().then(function(extensions) {
if (extensions && !$.isEmptyObject(extensions)) {
var extensionValues = [];
for (var uuid in extensions) {
@@ -204,7 +204,7 @@ function($, messages, dbusProxy, extensionUtils, templates) {
var uuid = extension.uuid;
function uninstall() {
- dbusProxy.UninstallExtension(uuid).done(function(result) {
+ dbusProxy.UninstallExtension(uuid).then(function(result) {
if (result) {
$elem.fadeOut({ queue: false }).slideUp({ queue: false });
messages.addInfo(templates.get('extensions/uninstall')(extension));
@@ -261,8 +261,8 @@ function($, messages, dbusProxy, extensionUtils, templates) {
var $form = $(this);
var uuid = $form.data('uuid');
var $textarea = $form.find('textarea');
- dbusProxy.GetExtensionInfo(uuid).done(function(meta) {
- dbusProxy.GetErrors($form.data('uuid')).done(function(errors) {
+ dbusProxy.GetExtensionInfo(uuid).then(function(meta) {
+ dbusProxy.GetErrors($form.data('uuid')).then(function(errors) {
var context = { sv: dbusProxy.ShellVersion,
ev: (meta && meta.version) ? meta.version : null,
errors: errors };
@@ -292,7 +292,7 @@ function($, messages, dbusProxy, extensionUtils, templates) {
}
});
- dbusProxy.GetExtensionInfo(uuid).done(function(meta) {
+ dbusProxy.GetExtensionInfo(uuid).then(function(meta) {
addExtensionSwitch(uuid, $extension, meta);
});
});
diff --git a/sweettooth/static/js/versions/common/common.js b/sweettooth/static/js/versions/common/common.js
index 6ae9bc4..ba7f1ea 100644
--- a/sweettooth/static/js/versions/common/common.js
+++ b/sweettooth/static/js/versions/common/common.js
@@ -4,23 +4,21 @@ define(['jquery', 'dbus!API'], function($, API) {
"use strict";
function _makeRawPromise(result) {
- // Check if result is promise already
- if(isPromise(result))
- return result;
-
return (new $.Deferred()).resolve(result);
}
function _makePromise(result) {
// Check if result is promise already
if(isPromise(result))
+ {
return result;
+ }
return _makeRawPromise(JSON.parse(result));
}
function isPromise(value) {
- return value && value.promise;
+ return value && typeof(value.then) == 'function';
}
return {
@@ -56,7 +54,7 @@ define(['jquery', 'dbus!API'], function($, API) {
var result = API.installExtension(uuid);
if(isPromise(result))
- return result;
+ return result;
return _makeRawPromise('succeeded');
},
@@ -65,7 +63,7 @@ define(['jquery', 'dbus!API'], function($, API) {
var result = API.installExtension(uuid, "");
if(isPromise(result))
- return result;
+ return result;
return _makeRawPromise('succeeded');
},
@@ -75,7 +73,7 @@ define(['jquery', 'dbus!API'], function($, API) {
var result = API.installExtension(uuid, d.done.bind(d), d.fail.bind(d));
if(isPromise(result))
- return result;
+ return result;
return d;
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]