Implement Operation ujsx component with props and leaf node behavior
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
export { Operation } from "./operation.js";
|
||||
export type { OperationProps } from "./operation.js";
|
||||
export { Parallel } from "./parallel.js";
|
||||
export type { ParallelProps } from "./parallel.js";
|
||||
export { Sequential } from "./sequential.js";
|
||||
|
||||
@@ -1 +1,32 @@
|
||||
export {};
|
||||
import type { UComponent, UElement, UNode, UniversalProps } from "@alkdev/ujsx";
|
||||
import type { PropValue } from "@alkdev/ujsx";
|
||||
|
||||
export interface OperationProps extends UniversalProps {
|
||||
name: string;
|
||||
input?: PropValue;
|
||||
retries?: number;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export const Operation: UComponent<OperationProps> = (
|
||||
props: OperationProps & { children?: UNode[] },
|
||||
): UElement => {
|
||||
const { name, input, retries, timeout, children, ...rest } = props;
|
||||
const elementProps: UniversalProps = { ...rest, name };
|
||||
if (input !== undefined) {
|
||||
elementProps.input = input;
|
||||
}
|
||||
if (retries !== undefined) {
|
||||
elementProps.retries = retries;
|
||||
}
|
||||
if (timeout !== undefined) {
|
||||
elementProps.timeout = timeout;
|
||||
}
|
||||
return {
|
||||
type: "operation",
|
||||
props: elementProps,
|
||||
children: [],
|
||||
};
|
||||
};
|
||||
|
||||
Operation.displayName = "Operation";
|
||||
Reference in New Issue
Block a user