Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/xml_renderer/mod.ts>default

An npm/browser module for easy matching XML and XPath to React Components and other stuff
Go to Latest
class default
import { default } from "https://deno.land/x/xml_renderer@5.0.7/mod.ts";

Constructors

new
default(...sets: Registry<MetadataGeneric>[])

A class that you instantiate to contain "metadata" associated with certain XML nodes. The metadata could be anything, but in context of being an "xml renderer" you'll probably want to use it for templates or React components.

See also GenericRenderer and ReactRenderer which extend the Registry class and add a .render() method to it.

Render functions (metadata) are associated with XML nodes via an XPath test. For any given node, the renderer will use the metadata associated the most specific test that matches the node.

Type Parameters

MetadataGeneric

Properties

protected
sets: { test: RegistrySelector; value: MetadataGeneric; }[]

All test/value sets known to this registery. Is kept in descending order of test specificity because Registry.optimize is always called when modifying this set through public methods.

readonly
length

Methods

private
optimize(): void

Reorders the sets based on XPath test specificity so that an Array#find finds the closest matching test first.

For example <b /> could match tests self::b as well as self::b[not(child::*)], but the latter is more specific so it wins.

This method is private because it is already called at all relevant times. Calling it again will normally not yield any different results.

add(test: RegistrySelector, value: MetadataGeneric): this

Add a test/value set to the registry, and optimizes (Registry.optimize).

find(node: Node): MetadataGeneric | undefined

Retrieve the metadata that was associated with this node before. If there are several rules that match, .find gives you only the value of the best match.

merge(...sets: Registry<MetadataGeneric>[]): this

Merges other registry instances into this one, and optimizes (Registry.optimize) when done.

overwrite(test: RegistrySelector, value: MetadataGeneric): this
remove(test: RegistrySelector): this

Remove a test/value set from the registry. This is the opposite of the Registry.add method.