Skip to content

Instantly share code, notes, and snippets.

@justin-lyon
Last active July 27, 2018 13:29
Show Gist options
  • Save justin-lyon/d515a51885ccc168fdca05653e945346 to your computer and use it in GitHub Desktop.
Save justin-lyon/d515a51885ccc168fdca05653e945346 to your computer and use it in GitHub Desktop.
/* MyLightningComponentHelper.js */
({
requestAccounts: function(cmp) {
var auraAction = cmp.get("c.getLimitedAccounts");
auraAction.setParams({
limitter: 10
});
acumen.promisify(auraAction)
.then(function(auraRes) {
console.log("res", auraRes.getReturnValue());
})
.catch(function(auraRes) {
console.error("err", auraRes.getErrors());
});
}
})
/* acumen-promisify.js */
window.acumen = (function Promiser(acumen) {
var promisify = function(auraAction) {
return new Promise(function(resolve, reject) {
auraAction.setCallback(this, function(res) {
var state = res.getState();
if(state === "SUCCESS") {
resolve(res);
} else {
reject(res);
}
});
$A.enqueueAction(auraAction);
});
};
acumen.promisify = promisify;
return acumen;
})(window.acumen || {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment