diff --git a/app.js b/app.js index c14ac69..a3e06f2 100644 --- a/app.js +++ b/app.js @@ -1 +1,6 @@ -/** @type {Van.State} */ \ No newline at end of file +const state = van.state(7); +van.add(document.body, van.tags.div({onclick() + { + state.val++; + } +}, state)); \ No newline at end of file diff --git a/deno.json b/deno.json index fdb2857..3c0c54e 100644 --- a/deno.json +++ b/deno.json @@ -10,7 +10,6 @@ ] }, "imports": { - "test": "https://esm.sh/react", "entry": "./app.js" } } diff --git a/index.html b/index.html index c2a0572..76f06ac 100644 --- a/index.html +++ b/index.html @@ -3,13 +3,16 @@ Document - - - diff --git a/van.d.ts b/van.d.ts index f16a02d..b2bb12d 100644 --- a/van.d.ts +++ b/van.d.ts @@ -1,69 +1,74 @@ -export {} declare global { namespace VanX { - type StateOf = { readonly [K in keyof T]: Van.State } - type ValueType = T extends (infer V)[] ? V : T[keyof T] - type KeyType = T extends unknown[] ? number : string - type ReplacementFunc = - T extends (infer V)[] ? (items: V[]) => readonly V[] : - (items: [string, T[keyof T]][]) => readonly [string, T[keyof T]][] + type StateOf = { readonly [K in keyof T]: Van.State } + type ValueType = T extends (infer V)[] ? V : T[keyof T] + type KeyType = T extends unknown[] ? number : string + type ReplacementFunc = + T extends (infer V)[] ? (items: V[]) => readonly V[] : + (items: [string, T[keyof T]][]) => readonly [string, T[keyof T]][] } namespace Van { - interface State { - val: T - readonly oldVal: T - readonly rawVal: T - } - - // Defining readonly view of State for covariance. - // Basically we want StateView to implement StateView - type StateView = Readonly> - - type Val = State | T - - type Primitive = string | number | boolean | bigint - - // deno-lint-ignore no-explicit-any - type PropValue = Primitive | ((e: any) => void) | null - - type PropValueOrDerived = PropValue | StateView | (() => PropValue) - - type Props = Record & { class?: PropValueOrDerived; is?: string } - - type PropsWithKnownKeys = Partial<{[K in keyof ElementType]: PropValueOrDerived}> - - type ValidChildDomValue = Primitive | Node | null | undefined - - type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element) - - type ChildDom = ValidChildDomValue | StateView | BindingFunc | readonly ChildDom[] - - type TagFunc = (first?: Props & PropsWithKnownKeys | ChildDom, ...rest: readonly ChildDom[]) => Result - - type Tags = Readonly>> & { - [K in keyof HTMLElementTagNameMap]: TagFunc - } + interface State { + val: T + readonly oldVal: T + readonly rawVal: T + } + + // Defining readonly view of State for covariance. + // Basically we want StateView to implement StateView + type StateView = Readonly> + + type Val = State | T + + type Primitive = string | number | boolean | bigint + + // deno-lint-ignore no-explicit-any + type PropValue = Primitive | ((e: any) => void) | null + + type PropValueOrDerived = PropValue | StateView | (() => PropValue) + + type Props = Record & { class?: PropValueOrDerived; is?: string } + + type PropsWithKnownKeys = Partial<{[K in keyof ElementType]: PropValueOrDerived}> + + type ValidChildDomValue = Primitive | Node | null | undefined + + type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element) + + type ChildDom = ValidChildDomValue | StateView | BindingFunc | readonly ChildDom[] + + type TagFunc = (first?: Props & PropsWithKnownKeys | ChildDom, ...rest: readonly ChildDom[]) => Result + + type Tags = Readonly>> & { + [K in keyof HTMLElementTagNameMap]: TagFunc + } } + + const van:MembersVan; + const vanX:MembersVanX; +} - const van:{ - readonly state: (initVal: T)=> Van.State - readonly derive: (f: () => T) => Van.State - readonly add: (dom: Element, ...children: readonly Van.ChildDom[]) => Element - readonly tags: Van.Tags & ((namespaceURI: string) => Readonly>>) - readonly hydrate: (dom: T, f: (dom: T) => T | null | undefined) => T - }; - const vanX: { - readonly calc: (f: () => R) => R - readonly reactive: (obj: T) => T - readonly noreactive: (obj: T) => T - readonly stateFields: (obj: T) => VanX.StateOf - readonly raw: (obj: T) => T - readonly list: (container: (() => ElementType) | ElementType, items: T,itemFunc: (v: Van.State>, deleter: () => void, k: VanX.KeyType) => Node) => ElementType - readonly replace: (obj: T, replacement: VanX.ReplacementFunc | T) => T - readonly compact: (obj: T) => T - }; -} \ No newline at end of file +type MembersVan = { + readonly state: (initVal: T)=> Van.State + readonly derive: (f: () => T) => Van.State + readonly add: (dom: Element, ...children: readonly Van.ChildDom[]) => Element + readonly tags: Van.Tags & ((namespaceURI: string) => Readonly>>) + readonly hydrate: (dom: T, f: (dom: T) => T | null | undefined) => T +} +type MembersVanX = { + readonly calc: (f: () => R) => R + readonly reactive: (obj: T) => T + readonly noreactive: (obj: T) => T + readonly stateFields: (obj: T) => VanX.StateOf + readonly raw: (obj: T) => T + readonly list: (container: (() => ElementType) | ElementType, items: T,itemFunc: (v: Van.State>, deleter: () => void, k: VanX.KeyType) => Node) => ElementType + readonly replace: (obj: T, replacement: VanX.ReplacementFunc | T) => T + readonly compact: (obj: T) => T +} + +export const Van: MembersVan; +export const VanX: MembersVanX; \ No newline at end of file