Created
January 6, 2019 07:24
-
-
Save xgeek-net/d6e487e751ad2331bea2a462f152633b to your computer and use it in GitHub Desktop.
SampleAuraHelper.js Lightning Component
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
({ | |
/** | |
* Call Apex Server-Side method in Promise | |
*/ | |
sendRequest : function(cmp, methodName, params){ | |
return new Promise($A.getCallback(function(resolve, reject) { | |
var action = cmp.get(methodName); | |
action.setParams(params); | |
action.setCallback(self, function(res) { | |
var state = res.getState(); | |
if(state === 'SUCCESS') { | |
resolve(res.getReturnValue()); | |
} else if(state === 'ERROR') { | |
reject(action.getError()) | |
} | |
}); | |
$A.enqueueAction(action); | |
})); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment