[extensions-web] Assume that API methods may return deferred object.
- From: Olav Vitters <ovitters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Assume that API methods may return deferred object.
- Date: Sat, 24 Sep 2016 11:49:35 +0000 (UTC)
commit b576313701842acf00465e92d181b05d36a0832c
Author: Yuri Konotopov <ykonotopov gmail com>
Date: Wed Jan 6 22:40:48 2016 +0300
Assume that API methods may return deferred object.
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=760225
sweettooth/static/js/versions/common/common.js | 32 ++++++++++++++++++++---
1 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/static/js/versions/common/common.js b/sweettooth/static/js/versions/common/common.js
index db7faca..6ae9bc4 100644
--- a/sweettooth/static/js/versions/common/common.js
+++ b/sweettooth/static/js/versions/common/common.js
@@ -4,15 +4,25 @@ define(['jquery', 'dbus!API'], function($, API) {
"use strict";
function _makeRawPromise(result) {
- // Make a new completed promise -- when we move the plugin
- // over to async, we can remove this.
+ // 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 {
_makePromise: _makePromise,
@@ -43,18 +53,30 @@ define(['jquery', 'dbus!API'], function($, API) {
},
InstallExtensionOne: function(uuid) {
- API.installExtension(uuid);
+ var result = API.installExtension(uuid);
+
+ if(isPromise(result))
+ return result;
+
return _makeRawPromise('succeeded');
},
InstallExtensionTwo: function(uuid) {
- API.installExtension(uuid, "");
+ var result = API.installExtension(uuid, "");
+
+ if(isPromise(result))
+ return result;
+
return _makeRawPromise('succeeded');
},
InstallExtensionAsync: function(uuid) {
var d = new $.Deferred();
- API.installExtension(uuid, d.done.bind(d), d.fail.bind(d));
+ var result = API.installExtension(uuid, d.done.bind(d), d.fail.bind(d));
+
+ if(isPromise(result))
+ return result;
+
return d;
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]