@vaadin/hilla-react-signals
Version:
Signals for Hilla React
89 lines (88 loc) • 3.58 kB
TypeScript
export type Id = string;
export type SignalCommand = Readonly<{
commandId: Id;
targetNodeId: Id;
'@type': string;
}>;
type CreateCommandType<T extends string, E extends Record<string, unknown> = Record<never, never>> = Readonly<{
'@type': T;
}> & Readonly<E> & SignalCommand;
export type ValueCondition<V> = CreateCommandType<'value', {
expectedValue: V;
}>;
export declare function createValueCondition<V>(targetNodeId: Id, expectedValue: V): ValueCondition<V>;
export type SetCommand<V> = CreateCommandType<'set', {
value: V;
}>;
export declare function createSetCommand<V>(targetNodeId: Id, value: V): SetCommand<V>;
export type IncrementCommand = CreateCommandType<'inc', {
delta: number;
}>;
export declare function createIncrementCommand(targetNodeId: Id, delta: number): IncrementCommand;
export type TransactionCommand = CreateCommandType<'tx', {
commands: SignalCommand[];
}>;
export declare function createTransactionCommand(commands: SignalCommand[]): TransactionCommand;
export type InsertCommand<V> = CreateCommandType<'insert', {
value: V;
position: ListPosition;
}>;
export declare const ZERO: Id;
export declare function createInsertCommand<V>(targetNodeId: Id, value: V, position: ListPosition): InsertCommand<V>;
export type ListPosition = {
after?: Id | null;
before?: Id | null;
};
export declare const EDGE: Id;
export declare const ListPosition: {
first(): ListPosition;
last(): ListPosition;
after(signal: {
id: Id;
} | null): ListPosition;
before(signal: {
id: Id;
} | null): ListPosition;
between(after: {
id: Id;
} | null, before: {
id: Id;
} | null): ListPosition;
};
export type AdoptAtCommand = CreateCommandType<'at', {
childId: Id;
position: ListPosition;
}>;
export declare function createAdoptAtCommand(targetNodeId: Id, childId: Id, position: ListPosition): AdoptAtCommand;
export type PositionCondition = CreateCommandType<'pos', {
childId: Id;
expectedPosition: ListPosition;
}>;
export declare function createPositionCondition(targetNodeId: Id, childId: Id, expectedPosition: ListPosition): PositionCondition;
export type RemoveCommand = CreateCommandType<'remove', {
expectedParentId: Id;
}>;
export declare function createRemoveCommand(targetNodeId: Id, expectedParentId: Id): RemoveCommand;
export type Node = {
'@type': string;
parent: Id | null;
lastUpdate: Id | null;
scopeOwner: Id | null;
value?: unknown;
listChildren: Id[];
mapChildren: Record<string, Id>;
};
export type SnapshotCommand = CreateCommandType<'snapshot', {
nodes: Record<Id, Node>;
}>;
export declare function createSnapshotCommand(nodes: Record<Id, Node>): SnapshotCommand;
export declare function isSetCommand<V>(command: unknown): command is SetCommand<V>;
export declare function isValueCondition<V>(command: unknown): command is ValueCondition<V>;
export declare function isIncrementCommand(command: unknown): command is IncrementCommand;
export declare function isTransactionCommand(command: unknown): command is TransactionCommand;
export declare function isInsertCommand<V>(command: unknown): command is InsertCommand<V>;
export declare function isAdoptAtCommand(command: unknown): command is AdoptAtCommand;
export declare function isPositionCondition(command: unknown): command is PositionCondition;
export declare function isRemoveCommand(command: unknown): command is RemoveCommand;
export declare function isSnapshotCommand(command: unknown): command is SnapshotCommand;
export {};