Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(923)

Unified Diff: remoting/webapp/base/js/base.js

Issue 848993002: Improve apps v2 upgrade UX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address outstanding feedbacks Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/base/html/main.css ('k') | remoting/webapp/crd/html/ui_me2me.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/base/js/base.js
diff --git a/remoting/webapp/base/js/base.js b/remoting/webapp/base/js/base.js
index 8111174821a0ccff799d31e22cf87a07d7bca28c..86c91565bb9f1907eaa792dbafeb4dcb5f0e187f 100644
--- a/remoting/webapp/base/js/base.js
+++ b/remoting/webapp/base/js/base.js
@@ -270,6 +270,29 @@ base.Promise.negate = function(promise) {
};
/**
+ * Converts a |method| with callbacks into a Promise.
+ *
+ * @param {Function} method
+ * @param {Array} params
+ * @param {*=} opt_context
+ * @param {boolean=} opt_hasErrorHandler whether the method has an error handler
+ * @return {Promise}
+ */
+base.Promise.as = function(method, params, opt_context, opt_hasErrorHandler) {
+ return new Promise(function(resolve, reject) {
+ params.push(resolve);
+ if (opt_hasErrorHandler) {
+ params.push(reject);
+ }
+ try {
+ method.apply(opt_context, params);
+ } catch (/** @type {*} */ e) {
+ reject(e);
+ }
+ });
+};
+
+/**
* A mixin for classes with events.
*
* For example, to create an alarm event for SmokeDetector:
« no previous file with comments | « remoting/webapp/base/html/main.css ('k') | remoting/webapp/crd/html/ui_me2me.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698