浏览代码

Use async/await instead of explicit promises

JC Brand 6 年之前
父节点
当前提交
370c4c84d9
共有 2 个文件被更改,包括 12 次插入28 次删除
  1. 7 14
      dist/converse.js
  2. 5 14
      src/headless/converse-disco.js

+ 7 - 14
dist/converse.js

@@ -64494,27 +64494,20 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
         });
         });
       },
       },
 
 
-      hasFeature(feature) {
+      async hasFeature(feature) {
         /* Returns a Promise which resolves with a map indicating
         /* Returns a Promise which resolves with a map indicating
          * whether a given feature is supported.
          * whether a given feature is supported.
          *
          *
          * Parameters:
          * Parameters:
          *    (String) feature - The feature that might be supported.
          *    (String) feature - The feature that might be supported.
          */
          */
-        const entity = this;
-        return new Promise((resolve, reject) => {
-          function fulfillPromise() {
-            if (entity.features.findWhere({
-              'var': feature
-            })) {
-              resolve(entity);
-            } else {
-              resolve();
-            }
-          }
+        await this.waitUntilFeaturesDiscovered;
 
 
-          entity.waitUntilFeaturesDiscovered.then(fulfillPromise).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
-        });
+        if (this.features.findWhere({
+          'var': feature
+        })) {
+          return this;
+        }
       },
       },
 
 
       onFeatureAdded(feature) {
       onFeatureAdded(feature) {

+ 5 - 14
src/headless/converse-disco.js

@@ -79,26 +79,17 @@ converse.plugins.add('converse-disco', {
                 });
                 });
             },
             },
 
 
-            hasFeature (feature) {
+            async hasFeature (feature) {
                 /* Returns a Promise which resolves with a map indicating
                 /* Returns a Promise which resolves with a map indicating
                  * whether a given feature is supported.
                  * whether a given feature is supported.
                  *
                  *
                  * Parameters:
                  * Parameters:
                  *    (String) feature - The feature that might be supported.
                  *    (String) feature - The feature that might be supported.
                  */
                  */
-                const entity = this;
-                return new Promise((resolve, reject) => {
-                    function fulfillPromise () {
-                        if (entity.features.findWhere({'var': feature})) {
-                            resolve(entity);
-                        } else {
-                            resolve();
-                        }
-                    }
-                    entity.waitUntilFeaturesDiscovered
-                        .then(fulfillPromise)
-                        .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
-                });
+                await this.waitUntilFeaturesDiscovered
+                if (this.features.findWhere({'var': feature})) {
+                    return this;
+                }
             },
             },
 
 
             onFeatureAdded (feature) {
             onFeatureAdded (feature) {