-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathvan.debug.d.ts
More file actions
48 lines (32 loc) · 1.73 KB
/
van.debug.d.ts
File metadata and controls
48 lines (32 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
export interface State<T> {
val: T
readonly oldVal: T
readonly rawVal: T
}
// Defining readonly view of State<T> for covariance.
// Basically we want StateView<string> to implement StateView<string | number>
export type StateView<T> = Readonly<State<T>>
export type Val<T> = State<T> | T
export type Primitive = string | number | boolean | bigint
export type PropValue = Primitive | ((e: any) => void) | null
export type PropValueOrDerived = PropValue | StateView<PropValue> | (() => PropValue)
export type Props = Record<string, PropValueOrDerived> & { class?: PropValueOrDerived; is?: string }
export type PropsWithKnownKeys<ElementType> = Partial<{[K in keyof ElementType]: PropValueOrDerived}>
export type ValidChildDomValue = Primitive | Node | null | undefined
export type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element)
export type ChildDom = ValidChildDomValue | StateView<Primitive | null | undefined> | BindingFunc | readonly ChildDom[]
export type TagFunc<Result> = (first?: Props & PropsWithKnownKeys<Result> | ChildDom, ...rest: readonly ChildDom[]) => Result
type Tags = Readonly<Record<string, TagFunc<Element>>> & {
[K in keyof HTMLElementTagNameMap]: TagFunc<HTMLElementTagNameMap[K]>
}
declare function state<T>(): State<T>
declare function state<T>(initVal: T): State<T>
export interface Van {
readonly state: typeof state
readonly derive: <T>(f: () => T) => State<T>
readonly add: (dom: Element | DocumentFragment, ...children: readonly ChildDom[]) => Element
readonly tags: Tags & ((namespaceURI: string) => Readonly<Record<string, TagFunc<Element>>>)
readonly hydrate: <T extends Node>(dom: T, f: (dom: T) => T | null | undefined) => T
}
declare const van: Van
export default van