Options
All
  • Public
  • Public/Protected
  • All
Menu

Package html

@typed/html

A configurable virtual-dom library with first-class effects.

Index

Type aliases

AddElements

AddElements<E>: <A>(parentNode: Node, vNodes: A, referenceNode: Node | null) => Effects<E & CombinedEnvsOf<A>, void>

Insert child elements to a parent from a given reference

Type parameters

  • E

Type declaration

    • <A>(parentNode: Node, vNodes: A, referenceNode: Node | null): Effects<E & CombinedEnvsOf<A>, void>
    • Type parameters

      Parameters

      • parentNode: Node
      • vNodes: A
      • referenceNode: Node | null

      Returns Effects<E & CombinedEnvsOf<A>, void>

BubblingEventHandler

BubblingEventHandler<E, A, Map, K>: (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>

Providing just a function defaults to listing to bubbling events

Type parameters

  • E: {}

  • A: TagName

  • Map: {}

  • K: keyof Map

Type declaration

    • (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]): Effects<E, any>
    • Parameters

      • event: { currentTarget: NodeFrom<A>; type: K } & Map[K]

      Returns Effects<E, any>

ChildrenOf

ChildrenOf<A>:

Get the Children of a VNode

Type parameters

  • A

CombinedEnvsOf

CombinedEnvsOf<A>: UnNest<Flatten<ToConsList<A>, {}>>

Get the combined environments of a list of VNodes

Type parameters

  • A: keyof any[]

CreateElement

CreateElement<E>: <A>(vNode: A) => Effects<E & EnvOf<A>, void>

Given a vNode it creates an element for it

Type parameters

  • E

Type declaration

    • <A>(vNode: A): Effects<E & EnvOf<A>, void>
    • Type parameters

      Parameters

      • vNode: A

      Returns Effects<E & EnvOf<A>, void>

ElementToVNode

ElementToVNode<E>: (node: Text | Comment | HTMLElement | SVGElement) => Effects<E, VNode<{}>>

Converts a DOM node to a VNode for monomorphic patch function

Type parameters

  • E

Type declaration

    • (node: Text | Comment | HTMLElement | SVGElement): Effects<E, VNode<{}>>
    • Parameters

      • node: Text | Comment | HTMLElement | SVGElement

      Returns Effects<E, VNode<{}>>

ElementTypes

ElementTypes: HtmlVNode | SvgVNode

EnvOf

Get the combined environment of a VNode and it's children

Type parameters

  • A

EventHandler

EventHandler<E, A, Map, K>: BubblingEventHandler<E, A, Map, K> | EventHandlerWithOptions<E, A, Map, K>

Type parameters

  • E: {}

  • A: TagName

  • Map: {}

  • K: keyof Map

EventHandlerWithOptions

EventHandlerWithOptions<E, A, Map, K>: keyof [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]

Providing AddEventListenerOptions in a pair allows customizing how the event handler is registered.

Type parameters

  • E: {}

  • A: TagName

  • Map: {}

  • K: keyof Map

EventMapFrom

EventMapFrom<A>: A extends HtmlTagName ? A extends "body" ? HTMLBodyElementEventMap : A extends "frameset" ? HTMLFrameSetElementEventMap : A extends "marquee" ? HTMLMarqueeElementEventMap : A extends "media" ? HTMLMediaElementEventMap : HTMLElementEventMap : A extends SvgTagName ? SVGElementEventMap : never

Type parameters

  • A

EventsFrom

EventsFrom<E, A>: EventsFromMap<E, A, EventMapFrom<A>>

Type parameters

EventsFromMap

EventsFromMap<E, A, Map>: {}

Type parameters

Type declaration

HtmlTagName

HtmlTagName: keyof HTMLElementTagNameMap

KeyOf

KeyOf<A, Key>: {}

Type parameters

  • A

  • Key: PropertyKey

Type declaration

NodeFrom

NodeFrom<A>: A extends HtmlTagName ? HTMLElementTagNameMap[A] : A extends SvgTagName ? SVGElementTagNameMap[A] : never

Lookup an element type by it's tag name

Type parameters

NodeOf

NodeOf<A>: A extends TextVNode ? Text : A extends CommentVNode ? Comment : NodeFrom<TagNameOf<A>>

Get the Node of a given VNode

Type parameters

PatchElement

PatchElement<E>: <A, B>(previous: A, updated: B) => Effects<E & EnvOf<A> & EnvOf<B>, void>

Patch the differences between two vNodes

Type parameters

  • E

Type declaration

    • <A, B>(previous: A, updated: B): Effects<E & EnvOf<A> & EnvOf<B>, void>
    • Type parameters

      Parameters

      • previous: A
      • updated: B

      Returns Effects<E & EnvOf<A> & EnvOf<B>, void>

PatchFailure

PatchFailure: FailEnv<typeof PatchFailure, Error>

PropertiesOf

PropertiesOf<A>: {}

Get the user-editable properties of a given Node

Type parameters

  • A: Node

Type declaration

PropsFrom

PropsFrom<A>: PropertiesOf<NodeFrom<A>>

Lookup the properties of an element by tag name

Type parameters

RecordDiff

RecordDiff<K, A>: { removed: ReadonlyArray<keyof [K, A]>; updated: ReadonlyArray<keyof [K, A]> }

Type parameters

  • K: PropertyKey

  • A

Type declaration

  • Readonly removed: ReadonlyArray<keyof [K, A]>
  • Readonly updated: ReadonlyArray<keyof [K, A]>

RemoveElements

RemoveElements<E>: <A>(parentNode: Node, vNodes: A) => Effects<E & CombinedEnvsOf<A>, void>

Remove child elements from a given parent node. Must remove .ref on removed elements

Type parameters

  • E

Type declaration

    • <A>(parentNode: Node, vNodes: A): Effects<E & CombinedEnvsOf<A>, void>
    • Type parameters

      Parameters

      • parentNode: Node
      • vNodes: A

      Returns Effects<E & CombinedEnvsOf<A>, void>

StrMapDiff

StrMapDiff<A>: RecordDiff<string, A>

Type parameters

  • A

SvgTagName

SvgTagName: keyof SVGElementTagNameMap

TagName

TagNameOf

TagNameOf<A>: A extends HtmlVNode<any, infer R, any> ? R : A extends SvgVNode<any, infer R, any> ? R : never

Get the tag name of a VNode

Type parameters

  • A

UpdateAriaAttributes

UpdateAriaAttributes<E>: <A>(vNode: A, diff: StrMapDiff<string>) => Effects<E & EnvOf<A>, A>

Type parameters

  • E

Type declaration

UpdateAttributes

UpdateAttributes<E>: <A>(vNode: A, diff: StrMapDiff<string | undefined>) => Effects<E & EnvOf<A>, A>

Type parameters

  • E

Type declaration

UpdateChildren

UpdateChildren<E>: <A, B>(parentElement: Element, children: A, updatedChildren: B) => Effects<E & CombinedEnvsOf<A> & CombinedEnvsOf<B>, void>

Diff the children of an element

Type parameters

  • E

Type declaration

UpdateDataList

UpdateDataList<E>: <A>(vNode: A, diff: StrMapDiff<string>) => Effects<E & EnvOf<A>, A>

Type parameters

  • E

Type declaration

UpdateEventHandlers

UpdateEventHandlers<E>: <A>(vNode: A, diff: RecordDiff<keyof EventMapFrom<TagNameOf<A>>, EventHandler<EnvOf<A>, TagNameOf<A>, EventMapFrom<TagNameOf<A>>, keyof EventMapFrom<TagNameOf<A>>>>) => Effects<E, A>

Given an ElementVNode, the current events map, and the updated events map - perform the necessary updates to the given ElementVNode and returns that ElementVNode.

Type parameters

  • E: {}

Type declaration

UpdateProperties

UpdateProperties<E>: <A>(vNode: A, diff: RecordDiff<keyof PropsFrom<TagNameOf<A>>, ValuesOf<PropsFrom<TagNameOf<A>>>>) => Effects<E, A>

Type parameters

  • E

Type declaration

VNode

VNode<E, A, B>: TextVNode | CommentVNode | HtmlVNode<E, A, B> | SvgVNode<E, A, B>

A Virtual Node, used to represent a DOM element

Type parameters

VNodeEnv

VNodeEnv<A>: A extends HtmlVNode<infer E, any, any> ? E : A extends SvgVNode<infer E, any, any> ? E : unknown

Get the individual environment of a given VNode

Type parameters

  • A

Variables

Const PatchFailure

PatchFailure: unique symbol = Symbol.for('PatchFailure')

Const SVG_NAMESPACE

SVG_NAMESPACE: "http://www.w3.org/2000/svg" = `http://www.w3.org/2000/svg`

Const createElement

createElement: CreateElement<DomEnv> = function* <A extends VNode>(vNode: A) {const { document } = yield* get()const node = (isHtml(vNode)? document.createElement(vNode.tagName): isSvg(vNode)? document.createElementNS(SVG_NAMESPACE, vNode.tagName): isText(vNode)? document.createTextNode(vNode.text): document.createComment((vNode as CommentVNode).comment)) as NodeOf<A>vNode.node.current = Just.of(node)if (isHtml(vNode) || isSvg(vNode)) {yield* combine(createElementAttributesAndProps(vNode as any),vNode.children.length > 0 ? addElements(node, vNode.children, null) : Effect.of(null),)}return vNode} as CreateElement<DomEnv>

Functions

Const addElements

  • addElements(parentNode: Node, vNodes: A, referenceNode: null | Node): Generator<Env<{}, any>, void, any>

comment

createPatchEnv

diffAttributes

  • diffAttributes(currentMap: StrMap<string | undefined>, updatedMap: StrMap<string | undefined>): StrMapDiff<string | undefined>

diffRecordMap

Const elementToVNode

  • elementToVNode(node: Text | Comment | HTMLElement | SVGElement): Effects<unknown, VNode>

getKey

getNodeOrThrow

html

isBooleanAttribute

  • isBooleanAttribute(key: any): boolean

Const isBubblingEventHandler

  • isBubblingEventHandler<E, A, Map, K>(handler: EventHandler<E, A, Map, K>): handler is BubblingEventHandler<E, A, Map, K>

isComment

  • isComment(vNode: VNode): vNode is CommentVNode

Const isEventHandlerWithOptions

  • isEventHandlerWithOptions<E, A, Map, K>(handler: EventHandler<E, A, Map, K>): handler is EventHandlerWithOptions<E, A, Map, K>

isHtml

  • isHtml(vNode: VNode): vNode is HtmlVNode

isSvg

  • isSvg(vNode: VNode): vNode is SvgVNode

isText

  • isText(vNode: VNode): vNode is TextVNode

Const patchElement

  • patchElement<A, B>(elementVNode: A, vNode: B): Generator<Env<{}, any> | Env<{} & DomEnv<unknown>, any>, void, any>

patchOnRaf

  • patchOnRaf<E, A>(fn: () => HookEffects<E, A>, rootElement: HTMLElement): HookEffects<E & EnvOf<A> & RafEnv & PatchEnv<VNode, A> & PatchFailure & HooksManagerEnv, never>

Const removeElements

  • removeElements(parentNode: Node, vNodes: A): Generator<Env<{}, any>, void, any>

svg

text

Const updateAriaAttributes

  • updateAriaAttributes(vNode: A, __namedParameters: { removed: ReadonlyArray<[string, string]>; updated: ReadonlyArray<[string, string]> }): Generator<Env<{}, any>, A, any>
  • Parameters

    • vNode: A
    • __namedParameters: { removed: ReadonlyArray<[string, string]>; updated: ReadonlyArray<[string, string]> }
      • removed: ReadonlyArray<[string, string]>
      • updated: ReadonlyArray<[string, string]>

    Returns Generator<Env<{}, any>, A, any>

Const updateAttributes

  • updateAttributes(vNode: A, __namedParameters: { removed: ReadonlyArray<[string, undefined | string]>; updated: ReadonlyArray<[string, undefined | string]> }): Generator<Env<{}, any>, A, any>
  • Parameters

    • vNode: A
    • __namedParameters: { removed: ReadonlyArray<[string, undefined | string]>; updated: ReadonlyArray<[string, undefined | string]> }
      • removed: ReadonlyArray<[string, undefined | string]>
      • updated: ReadonlyArray<[string, undefined | string]>

    Returns Generator<Env<{}, any>, A, any>

Const updateChildren

  • updateChildren(parentElement: Element, current: A, updated: B): Generator<Env<DomEnv<unknown> & {}, any>, void, any>

Const updateDataList

  • updateDataList(vNode: A, __namedParameters: { removed: ReadonlyArray<[string, string]>; updated: ReadonlyArray<[string, string]> }): Generator<Env<{}, any>, A, any>
  • Parameters

    • vNode: A
    • __namedParameters: { removed: ReadonlyArray<[string, string]>; updated: ReadonlyArray<[string, string]> }
      • removed: ReadonlyArray<[string, string]>
      • updated: ReadonlyArray<[string, string]>

    Returns Generator<Env<{}, any>, A, any>

Const updateEventHandlers

  • updateEventHandlers(vNode: A, __namedParameters: { removed: ReadonlyArray<[keyof EventMapFrom<TagNameOf<A>>, ((event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>) | [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]]>; updated: ReadonlyArray<[keyof EventMapFrom<TagNameOf<A>>, ((event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>) | [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]]> }): Generator<Env<{}, any>, A, any>
  • Parameters

    • vNode: A
    • __namedParameters: { removed: ReadonlyArray<[keyof EventMapFrom<TagNameOf<A>>, ((event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>) | [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]]>; updated: ReadonlyArray<[keyof EventMapFrom<TagNameOf<A>>, ((event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>) | [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]]> }
      • removed: ReadonlyArray<[keyof EventMapFrom<TagNameOf<A>>, ((event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>) | [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]]>
      • updated: ReadonlyArray<[keyof EventMapFrom<TagNameOf<A>>, ((event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>) | [AddEventListenerOptions, (event: { currentTarget: NodeFrom<A>; type: K } & Map[K]) => Effects<E, any>]]>

    Returns Generator<Env<{}, any>, A, any>

Const updateProperties

  • updateProperties(vNode: A, __namedParameters: { removed: ReadonlyArray<[{ [K in keyof NodeFrom<TagNameOf<A>>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<TagNameOf<A>>]: IfEquals<{ [Key in K]: NodeFrom<TagNameOf<A>>[K]; }, { -readonly [Key in K]: NodeFrom<...>[K]; }, K, never>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof Nod..., { [K in keyof PropertiesOf<NodeFrom<TagNameOf<A>>>]: PropertiesOf<NodeFrom<TagNameOf<A>>>[K]; }[{ [K in keyof NodeFrom<...>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<...>]: IfEquals<...>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof NodeFrom<...>]]]>; updated: ReadonlyArray<[{ [K in keyof NodeFrom<TagNameOf<A>>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<TagNameOf<A>>]: IfEquals<{ [Key in K]: NodeFrom<TagNameOf<A>>[K]; }, { -readonly [Key in K]: NodeFrom<...>[K]; }, K, never>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof Nod..., { [K in keyof PropertiesOf<NodeFrom<TagNameOf<A>>>]: PropertiesOf<NodeFrom<TagNameOf<A>>>[K]; }[{ [K in keyof NodeFrom<...>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<...>]: IfEquals<...>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof NodeFrom<...>]]]> }): Generator<Env<{}, any>, A, any>
  • Parameters

    • vNode: A
    • __namedParameters: { removed: ReadonlyArray<[{ [K in keyof NodeFrom<TagNameOf<A>>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<TagNameOf<A>>]: IfEquals<{ [Key in K]: NodeFrom<TagNameOf<A>>[K]; }, { -readonly [Key in K]: NodeFrom<...>[K]; }, K, never>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof Nod..., { [K in keyof PropertiesOf<NodeFrom<TagNameOf<A>>>]: PropertiesOf<NodeFrom<TagNameOf<A>>>[K]; }[{ [K in keyof NodeFrom<...>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<...>]: IfEquals<...>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof NodeFrom<...>]]]>; updated: ReadonlyArray<[{ [K in keyof NodeFrom<TagNameOf<A>>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<TagNameOf<A>>]: IfEquals<{ [Key in K]: NodeFrom<TagNameOf<A>>[K]; }, { -readonly [Key in K]: NodeFrom<...>[K]; }, K, never>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof Nod..., { [K in keyof PropertiesOf<NodeFrom<TagNameOf<A>>>]: PropertiesOf<NodeFrom<TagNameOf<A>>>[K]; }[{ [K in keyof NodeFrom<...>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<...>]: IfEquals<...>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof NodeFrom<...>]]]> }
      • removed: ReadonlyArray<[{ [K in keyof NodeFrom<TagNameOf<A>>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<TagNameOf<A>>]: IfEquals<{ [Key in K]: NodeFrom<TagNameOf<A>>[K]; }, { -readonly [Key in K]: NodeFrom<...>[K]; }, K, never>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof Nod..., { [K in keyof PropertiesOf<NodeFrom<TagNameOf<A>>>]: PropertiesOf<NodeFrom<TagNameOf<A>>>[K]; }[{ [K in keyof NodeFrom<...>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<...>]: IfEquals<...>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof NodeFrom<...>]]]>
      • updated: ReadonlyArray<[{ [K in keyof NodeFrom<TagNameOf<A>>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<TagNameOf<A>>]: IfEquals<{ [Key in K]: NodeFrom<TagNameOf<A>>[K]; }, { -readonly [Key in K]: NodeFrom<...>[K]; }, K, never>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof Nod..., { [K in keyof PropertiesOf<NodeFrom<TagNameOf<A>>>]: PropertiesOf<NodeFrom<TagNameOf<A>>>[K]; }[{ [K in keyof NodeFrom<...>]: K extends ExcludedKeys ? never : K extends { [K in keyof NodeFrom<...>]: IfEquals<...>; }[keyof NodeFrom<...>] ? NodeFrom<...>[K] extends Json ? K : never : never; }[keyof NodeFrom<...>]]]>

    Returns Generator<Env<{}, any>, A, any>

useHookEnvUpdated

  • useHookEnvUpdated(env: HookEnvironment, onUpdated: () => Disposable): ChannelEffects<HookEnv & TimerEnv, Disposable>
  • Listen for updated events regarding a particular hook environment.

    Parameters

    • env: HookEnvironment
    • onUpdated: () => Disposable
        • (): Disposable
        • Returns Disposable

    Returns ChannelEffects<HookEnv & TimerEnv, Disposable>

useKeyManager

  • useKeyManager<E, A>(key: object, render: () => HookEffects<E, A>): ChannelEffects<HookEnv & TimerEnv & PatchEnv<VNode, A> & E & EnvOf<A>, A>
  • Used to manage a help manage re-rendering a patchable instance

    Type parameters

    Parameters

    • key: object
    • render: () => HookEffects<E, A>
        • (): HookEffects<E, A>
        • Returns HookEffects<E, A>

    Returns ChannelEffects<HookEnv & TimerEnv & PatchEnv<VNode, A> & E & EnvOf<A>, A>

useListManager

  • useListManager<A, B, E>(list: ReadonlyArray<A>, identify: Arity1<A, B>, computation: (value: A, index: number) => HookEffects<E, VNode>): HookEffects<E & TimerEnv & HooksManagerEnv & PatchEnv<VNode, VNode>, ReadonlyArray<VNode>>

useMatchManager

  • useMatchManager<A, E, B>(matchAgainst: A, matches: ReadonlyArray<Match<A, () => HookEffects<E, B>>>): ChannelEffects<E & TimerEnv & HookEnv & PatchEnv<VNode, B>, Maybe<B>>

vNodesAreEqual

  • vNodesAreEqual<A, B>(a: A, b: B): boolean

Generated using TypeDoc