Skip to content

Instantly share code, notes, and snippets.

@scottmo
Created May 7, 2019 15:34
Show Gist options
  • Save scottmo/7898fa7d15ec74dd1c0b933d8113ae36 to your computer and use it in GitHub Desktop.
Save scottmo/7898fa7d15ec74dd1c0b933d8113ae36 to your computer and use it in GitHub Desktop.

Revisions

  1. scottmo created this gist May 7, 2019.
    18 changes: 18 additions & 0 deletions createComponentPromise.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    function createComponent(cmp, attributes) {
    return new Promise(function(resolve, reject) {
    function doCreateComponent() {
    $A.createComponent(cmpDef, attributes, function(newCmp, status, errorMsg) {
    if (newCmp && status === 'SUCCESS') {
    resolve(newCmp);
    } else if (status === 'ERROR') {
    reject(errorMsg);
    } else if (status === 'INCOMPLETE') {
    $A.getEvt('markup://force:showOfflineMessage').fire({
    retryFunction: doCreateComponent
    });
    }
    });
    }
    doCreateComponent();
    });
    }