Guest User

Untitled

a guest
Dec 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. var promise = $A.enqueueAction(action);
  2. promise.then(function(result){
  3. // Do something
  4. });
  5.  
  6. callAction : function( component, actionName, params ) {
  7.  
  8. var helper = this;
  9.  
  10. var p = new Promise( function( resolve, reject ) {
  11.  
  12. helper.showSpinner( component );
  13.  
  14. var action = component.get( actionName );
  15.  
  16. if ( params ) {
  17. action.setParams( params );
  18. }
  19.  
  20. action.setCallback( helper, function( response ) {
  21.  
  22. helper.hideSpinner( component );
  23.  
  24. if ( component.isValid() && response.getState() === 'SUCCESS' ) {
  25.  
  26. resolve( response.getReturnValue() );
  27.  
  28. } else {
  29.  
  30. console.error( 'Error calling action "' + actionName + '" with state: ' + response.getState() );
  31.  
  32. reject( response.getError(), response.getState() );
  33.  
  34. }
  35. });
  36.  
  37. $A.enqueueAction( action );
  38.  
  39. });
  40.  
  41. return p;
  42. },
  43.  
  44. someMethod : function( component, event, helper ) {
  45.  
  46. var helper = this;
  47.  
  48. helper.callAction( component, 'c.someApexMethod', {
  49.  
  50. 'someParam' : component.get( 'v.someAttribute' )
  51.  
  52. }).then( $A.getCallback( function( data ) {
  53.  
  54. component.set( 'v.anotherAttribute', data );
  55.  
  56. })).catch( $A.getCallback( function( errors, state ) {
  57.  
  58. helper.logActionErrors( component, errors );
  59.  
  60. }));
  61.  
  62. }
  63.  
  64. component.lax.enqueue('c.getParentValue')
  65. .then(parentValue => {
  66. component.set('v.parentValue', parentValue);
  67. return component.lax.enqueue('c.getDependentValue', { parentValue: parentValue });
  68. })
  69. .then(dependentValue => {
  70. component.set('v.dependentValue', dependentValue);
  71. });
Add Comment
Please, Sign In to add comment