@tempots/dom
Version:
Fully-typed frontend framework alternative to React and Angular
29 lines (28 loc) • 1.6 kB
TypeScript
import { TNode, Renderable } from '../types/domain';
import { Signal } from '../std/signal';
import { Value } from '../std/value';
export type NillifyValue<T> = Value<T | null | undefined> | Value<T | undefined> | Value<T | null>;
export type Id<T> = {} & {
[P in keyof T]: T[P];
};
export type Merge<A, B> = Id<A & B>;
export type NonNillable<T> = Merge<T, {}>;
/**
* Represents a function that ensures a signal has a value before rendering a TNode.
*
* @typeParam T - The type of the signal value.
* @param value - The signal or literal that may hold a value of type T or null or undefined.
* @param then - The function that returns a TNode when the signal has a value. It takes a signal of the non-nullable type of T.
* @param otherwise - The function that returns a TNode when the signal does not have a value.
* @returns A renderable function that ensures the signal has a value before rendering a TNode.
* @public
*/
export declare const Ensure: <T>(value: NillifyValue<T>, then: (value: Signal<NonNillable<T>>) => TNode, otherwise?: () => TNode) => Renderable;
/**
* Ensures that all signals have a value before rendering a TNode.
*
* @param signals - The signals to ensure have a value.
* @returns A renderable function that ensures all signals have a value before rendering a TNode.
* @public
*/
export declare const EnsureAll: <T extends readonly Value<any>[]>(...signals: { [K in keyof T]: NillifyValue<T[K]>; }) => (callback: (...values: { [K in keyof T]: Signal<NonNillable<T[K] extends Value<infer U> ? U : never>>; }) => TNode, otherwise?: () => TNode) => Renderable;