-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
120 changed files
with
960 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ | |
}, | ||
"dependencies": { | ||
"terser": "^5.20.0", | ||
"vanjs-core": "^1.5.1" | ||
"vanjs-core": "^1.5.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,6 @@ | |
"vite": "^4.3.9" | ||
}, | ||
"dependencies": { | ||
"vanjs-core": "^1.5.1" | ||
"vanjs-core": "^1.5.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 } | ||
|
||
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, ...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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 } | ||
|
||
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, ...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 |
Oops, something went wrong.