Created
November 7, 2018 17:48
-
-
Save sohalloran/1c5d9881626c648fc9574ea635d88c42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" extensible="true"> | |
| <aura:method name="execApex" action="{! c.execApex }"> | |
| <aura:attribute name="callingComponent" type="Aura.Component" default="{! this }" /> | |
| <aura:attribute name="method" type="String" /> | |
| <aura:attribute name="params" type="Map" /> | |
| </aura:method> | |
| {! v.body } | |
| </aura:component> |
This file contains hidden or 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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | |
| <apiVersion>43.0</apiVersion> | |
| <description>Library contains methods to work with server side (APEX).</description> | |
| </AuraDefinitionBundle> |
This file contains hidden or 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
| ({ | |
| execApex: function(cmd, event, helper) { | |
| return helper.execApex(event.getParam('arguments')); | |
| }, | |
| }) |
This file contains hidden or 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
| ({ | |
| execApex: function (eventParams) { | |
| var d = new Date; | |
| var log = console.log.bind(console, eventParams.callingComponent ? eventParams.callingComponent.getName() : ''); | |
| log(`${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}`, 'start exec'); | |
| return new Promise($A.getCallback((resolve, reject) => { | |
| log(`${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}`, 'start promise'); | |
| let { callingComponent, method, params } = eventParams; | |
| let action = callingComponent.get('c.' + method); | |
| params && action.setParams(params); | |
| action.setCallback(this, function (response) { | |
| if ('SUCCESS' !== response.getState()) { | |
| console.error(response.getState(), response.getError()); | |
| log(`${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}`, 'reject'); | |
| reject(response); | |
| return; | |
| } | |
| log(`${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}`, 'resolve'); | |
| resolve(response.getReturnValue()); | |
| }); | |
| $A.enqueueAction(action); | |
| log(`${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}`, 'enqueueAction'); | |
| })); | |
| }, | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: