Skip to content

Commit

Permalink
Processing Step: Remove the check of action (Automattic#71485)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur791004 authored Dec 23, 2022
1 parent 7287b2e commit af98552
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,27 @@ const ProcessingStep: Step = function ( props ) {
const captureFlowException = useCaptureFlowException( props.flow, 'ProcessingStep' );

useEffect( () => {
if ( action ) {
( async () => {
if ( typeof action === 'function' ) {
try {
const destination = await action();
// Don't call submit() directly; instead, turn on a flag that signals we should call submit() next.
// This allows us to call the newest submit() created. Otherwise, we would be calling a submit()
// that is frozen from before we called action().
// We can now get the most up to date values from hooks inside the flow creating submit(),
// including the values that were updated during the action() running.
setDestinationState( destination );
setHasActionSuccessfullyRun( true );
} catch ( e ) {
// eslint-disable-next-line no-console
console.error( 'ProcessingStep failed:', e );
captureFlowException( e );
submit?.( {}, ProcessingResult.FAILURE );
}
} else {
submit?.( {}, ProcessingResult.NO_ACTION );
( async () => {
if ( typeof action === 'function' ) {
try {
const destination = await action();
// Don't call submit() directly; instead, turn on a flag that signals we should call submit() next.
// This allows us to call the newest submit() created. Otherwise, we would be calling a submit()
// that is frozen from before we called action().
// We can now get the most up to date values from hooks inside the flow creating submit(),
// including the values that were updated during the action() running.
setDestinationState( destination );
setHasActionSuccessfullyRun( true );
} catch ( e ) {
// eslint-disable-next-line no-console
console.error( 'ProcessingStep failed:', e );
captureFlowException( e );
submit?.( {}, ProcessingResult.FAILURE );
}
} )();
}
} else {
submit?.( {}, ProcessingResult.NO_ACTION );
}
} )();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ action ] );

Expand Down

0 comments on commit af98552

Please sign in to comment.