Skip to content

Commit

Permalink
Ensure generator functions using withSyncEvent() are wrapped correctl…
Browse files Browse the repository at this point in the history
…y to still be recognized as generator functions.
  • Loading branch information
felixarntz committed Jan 21, 2025
1 parent 524bf72 commit 21e51be
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/interactivity/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ export const isPlainObject = (
* @return Wrapped event callback.
*/
export const withSyncEvent = ( callback: Function ): Function => {
if ( callback?.constructor?.name === 'GeneratorFunction' ) {
const wrapped = function* ( ...args: any[] ) {
yield* callback( ...args );
};
wrapped.sync = true;
return wrapped;
}

const wrapped = ( ...args: any[] ) => callback( ...args );
wrapped.sync = true;
return wrapped;
Expand Down

0 comments on commit 21e51be

Please sign in to comment.