Last active
July 27, 2018 13:29
-
-
Save justin-lyon/d515a51885ccc168fdca05653e945346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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