From 33bc665cb81f4858288319d53be76850b282af2a Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Thu, 6 Feb 2025 13:17:36 -0500 Subject: [PATCH] ambient / global --- .vscode/settings.json | 3 -- app.js | 4 +- faux.d.ts | 2 - faux.js | 0 van.d.ts | 85 +++++++++++++++++++++++++++++++++--------- van.globals.d.ts.old | 10 ----- van.js | 2 - van.types.d.ts | 47 ----------------------- van.types.d.ts.old | 39 ------------------- van.x.globals.d.ts.old | 13 ------- van.x.types.d.ts.old | 9 ----- 11 files changed, 69 insertions(+), 145 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 faux.d.ts delete mode 100644 faux.js delete mode 100644 van.globals.d.ts.old delete mode 100644 van.js delete mode 100644 van.types.d.ts delete mode 100644 van.types.d.ts.old delete mode 100644 van.x.globals.d.ts.old delete mode 100644 van.x.types.d.ts.old diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b943dbc..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "deno.enable": true -} \ No newline at end of file diff --git a/app.js b/app.js index 8de5ed9..c14ac69 100644 --- a/app.js +++ b/app.js @@ -1,3 +1 @@ -import {van, vanX} from "./van.js"; - -van.state \ No newline at end of file +/** @type {Van.State} */ \ No newline at end of file diff --git a/faux.d.ts b/faux.d.ts deleted file mode 100644 index ec94706..0000000 --- a/faux.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export declare type Member =(s:string)=>Array; -export declare const Member:Member; \ No newline at end of file diff --git a/faux.js b/faux.js deleted file mode 100644 index e69de29..0000000 diff --git a/van.d.ts b/van.d.ts index 4664907..f16a02d 100644 --- a/van.d.ts +++ b/van.d.ts @@ -1,18 +1,69 @@ +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]][] + } -export 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 -} -export 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 -} + 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 + } + } + + 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 diff --git a/van.globals.d.ts.old b/van.globals.d.ts.old deleted file mode 100644 index e993a16..0000000 --- a/van.globals.d.ts.old +++ /dev/null @@ -1,10 +0,0 @@ -export {} -declare global { - 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 - } -} diff --git a/van.js b/van.js deleted file mode 100644 index 8dcbaa3..0000000 --- a/van.js +++ /dev/null @@ -1,2 +0,0 @@ -export const van = globalThis.van; -export const vanX = globalThis.vanX; \ No newline at end of file diff --git a/van.types.d.ts b/van.types.d.ts deleted file mode 100644 index 5b3a385..0000000 --- a/van.types.d.ts +++ /dev/null @@ -1,47 +0,0 @@ - -declare 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 - } -} -declare 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]][] -} \ No newline at end of file diff --git a/van.types.d.ts.old b/van.types.d.ts.old deleted file mode 100644 index 0c83f68..0000000 --- a/van.types.d.ts.old +++ /dev/null @@ -1,39 +0,0 @@ - -declare 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 - } - -} \ No newline at end of file diff --git a/van.x.globals.d.ts.old b/van.x.globals.d.ts.old deleted file mode 100644 index 81de377..0000000 --- a/van.x.globals.d.ts.old +++ /dev/null @@ -1,13 +0,0 @@ -export {}; -declare global { - 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 diff --git a/van.x.types.d.ts.old b/van.x.types.d.ts.old deleted file mode 100644 index 1337f96..0000000 --- a/van.x.types.d.ts.old +++ /dev/null @@ -1,9 +0,0 @@ -declare 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]][] -} \ No newline at end of file