Open fabiancook opened 3 years ago
The initial implementation of toString
is available here
It it marked as experimental.
It includes support for "this" to be bound to, which allows for customisation of how the string is generated. An example of this is the quirks of HTML, including script
requiring to contain a body
Usage of this can be seen here:
function isScalar(node: VNode) {
if (!node.scalar) return false;
const tags: unknown[] = ["script", "link", "meta"];
return !tags.includes(node.source);
}
function getBody(node: VNode, body: string) {
if (body) {
return `\n${body.split("\n").map(value => ` ${value}`).join("\n")}\n`;
}
if (node.source !== "script") {
return ""
}
return "\n";
}
const string = await toString.call({ isScalar, getBody }, view);
By default deno's typescript doesn't like the usage of a .then
function that isn't a "real promise", so this API may be unusable there. Potentially we can use a real promise, and assign our async iterator to it.
🚀 Feature Proposal
Produce a string from any vnode
Motivation
To output a vnode as a string for client usage.
Example
Consuming the result iteratively as it is generated:
Resolving the complete string: