Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var promise = $A.enqueueAction(action);
- promise.then(function(result){
- // Do something
- });
- callAction : function( component, actionName, params ) {
- var helper = this;
- var p = new Promise( function( resolve, reject ) {
- helper.showSpinner( component );
- var action = component.get( actionName );
- if ( params ) {
- action.setParams( params );
- }
- action.setCallback( helper, function( response ) {
- helper.hideSpinner( component );
- if ( component.isValid() && response.getState() === 'SUCCESS' ) {
- resolve( response.getReturnValue() );
- } else {
- console.error( 'Error calling action "' + actionName + '" with state: ' + response.getState() );
- reject( response.getError(), response.getState() );
- }
- });
- $A.enqueueAction( action );
- });
- return p;
- },
- someMethod : function( component, event, helper ) {
- var helper = this;
- helper.callAction( component, 'c.someApexMethod', {
- 'someParam' : component.get( 'v.someAttribute' )
- }).then( $A.getCallback( function( data ) {
- component.set( 'v.anotherAttribute', data );
- })).catch( $A.getCallback( function( errors, state ) {
- helper.logActionErrors( component, errors );
- }));
- }
- component.lax.enqueue('c.getParentValue')
- .then(parentValue => {
- component.set('v.parentValue', parentValue);
- return component.lax.enqueue('c.getDependentValue', { parentValue: parentValue });
- })
- .then(dependentValue => {
- component.set('v.dependentValue', dependentValue);
- });
Add Comment
Please, Sign In to add comment