Skip to content

Commit

Permalink
refactor: return plain values for simple executors
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Dec 11, 2024
1 parent d2c0ad0 commit e27b318
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/npm/@amazeelabs/executors/src/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
import { findExecutor, findExecutors, mergeExecutors } from './lib.js';
import type {
ExecutionState,
ExecutorFunction,
Executor,
OperationProps,
RegistryEntry,
} from './types.js';
Expand Down Expand Up @@ -56,13 +56,13 @@ export const useOperationExecutor: HookType = <
>(
id: TOperation,
variables?: OperationVariables<TOperation>,
): ExecutorFunction<TOperation> => {
): Executor<TOperation> => {
const { executors } = useContext(ExecutorsContext);
const executor = findExecutor(executors, id, variables);
if (executor instanceof Function) {
return (vars?: OperationVariables<TOperation>) => executor(id, vars);
}
return () => executor;
return executor;
};

export const useAllOperationExecutors: AllHookType = <
Expand Down
9 changes: 7 additions & 2 deletions packages/npm/@amazeelabs/executors/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import type {
} from '@amazeelabs/codegen-operation-ids';
import type { PropsWithChildren, ReactElement } from 'react';

import type { ExecutorFunction, OperationProps, RegistryEntry } from './types';
import type {
Executor,
ExecutorFunction,
OperationProps,
RegistryEntry,
} from './types';

export type { RegistryEntry } from './types';

Expand All @@ -15,7 +20,7 @@ export type Operation = <TOperation extends AnyOperationId>(
export type useOperationExecutor = <TOperation extends AnyOperationId>(
id: TOperation,
variables?: OperationVariables<TOperation>,
) => ExecutorFunction<TOperation>;
) => Executor<TOperation>;

export type useAllOperationExecutors = <TOperation extends AnyOperationId>(
id: TOperation,
Expand Down

0 comments on commit e27b318

Please sign in to comment.