mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-22 11:39:34 -06:00
25 lines
812 B
Zig
25 lines
812 B
Zig
/// Test: Components with error union return type (!Component)
|
|
pub fn Page(allocator: zx.Allocator) zx.Component {
|
|
return (
|
|
<main @allocator={allocator}>
|
|
<Fallible success={true} />
|
|
<FallibleCtx success={true} />
|
|
</main>
|
|
);
|
|
}
|
|
|
|
/// Error union with allocator signature
|
|
const FallibleProps = struct { success: bool };
|
|
pub fn Fallible(allocator: zx.Allocator, props: FallibleProps) !zx.Component {
|
|
if (!props.success) return error.TestError;
|
|
return (<div @allocator={allocator}>Success</div>);
|
|
}
|
|
|
|
/// Error union with ComponentCtx signature
|
|
pub fn FallibleCtx(ctx: *zx.ComponentCtx(FallibleProps)) !zx.Component {
|
|
if (!ctx.props.success) return error.TestError;
|
|
return (<div @allocator={ctx.allocator}>Ctx Success</div>);
|
|
}
|
|
|
|
const zx = @import("zx");
|