Files
formipay/node_modules/@wordpress/redux-routine/src/runtime.ts
dwindown e8fbfb14c1 fix: prevent asset conflicts between React and Grid.js versions
Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-18 17:02:14 +07:00

73 lines
1.5 KiB
TypeScript

/**
* External dependencies
*/
import type { Control } from 'rungen';
import { create } from 'rungen';
import isPromise from 'is-promise';
import type { Dispatch, AnyAction } from 'redux';
/**
* Internal dependencies
*/
import { isActionOfType, isAction } from './is-action';
/**
* Create a co-routine runtime.
*
* @param controls Object of control handlers.
* @param dispatch Unhandled action dispatch.
*/
export default function createRuntime(
controls: Record<
string,
( value: any ) => Promise< boolean > | boolean
> = {},
dispatch: Dispatch
) {
const rungenControls = Object.entries( controls ).map(
( [ actionType, control ] ): Control =>
( value, next, iterate, yieldNext, yieldError ) => {
if ( ! isActionOfType( value, actionType ) ) {
return false;
}
const routine = control( value );
if ( isPromise( routine ) ) {
// Async control routine awaits resolution.
routine.then( yieldNext, yieldError );
} else {
yieldNext( routine );
}
return true;
}
);
const unhandledActionControl = (
value: AnyAction | unknown,
next: () => void
) => {
if ( ! isAction( value ) ) {
return false;
}
dispatch( value );
next();
return true;
};
rungenControls.push( unhandledActionControl );
const rungenRuntime = create( rungenControls );
return ( action: AnyAction | Generator ) =>
new Promise( ( resolve, reject ) =>
rungenRuntime(
action,
( result ) => {
if ( isAction( result ) ) {
dispatch( result );
}
resolve( result );
},
reject
)
);
}