elematic / heximal

Heximal is a web-based interactive document and notebook system
MIT License
119 stars 1 forks source link

[components] <h-bar> should accept more value types and expressions. #2

Open justinfagnani opened 2 months ago

justinfagnani commented 2 months ago

Specifying literal types

Literal primitives can use a type attribute that looks up a converter:

<h-var name="num" type="number" value="42"></h-var>
<h-var name="num" type="boolean" value="42"></h-var>

JSON could be supported as child content:

<h-var name="num" type="json">
{
  "foo": "bar"
}
</h-var>

It might be tempting to do HTML this way too:

<h-var name="num" type="html">
  <h1>Hello</h1>
</h-var>

But that HTML isn't isolated from the page, so it's probably always better to use a <template> instead:

<template id="hello">
  <h1>Hello</h1>
</template>

Along with some way of referencing a template's content from an expression.

Expressions

Expressions can use a .value property binding with expressions. The expression is evaluated outside of the <h-var> instance, and the result passed to the value.