horojs
Version:
A micro library for a reactive UI application.
31 lines (30 loc) • 1.16 kB
TypeScript
type Unsubscriber = () => void;
//TO-DO: remove unsubscriber after onDestroy hook will be added
type Subscribable<T> = {
(listner: (value: T) => void): Unsubscriber | void;
};
type Subscription<T> = {
(value: T): void;
};
type Subscriptions<T> = T extends infer K ? Subscription<K> : never;
interface Component {
unsubscribe(): void;
fragment: DocumentFragment;
}
type StaticInsertion = string | Component;
type DynamicInsertion = Subscribable<string | Component>;
type ValueInsertion = DynamicInsertion | StaticInsertion;
type Instertion = Subscriptions<GlobalEventHandlersEventMap[keyof GlobalEventHandlersEventMap]> | ValueInsertion;
declare function horo(template: TemplateStringsArray, ...insertions: Instertion[]): Component;
declare function mergeComponents(components: Component[]): Component;
type Dispatcher<Value> = {
(value: Value): void;
};
type State<Value> = {
(cb: (value: Value) => void): void;
};
declare function state<Value>(value: Value): [
State<Value>,
Dispatcher<Value>
];
export { horo, Component, StaticInsertion, Instertion as Instertions, DynamicInsertion, mergeComponents, state, Dispatcher, State };