be-promising aims to address two tricky issues when it comes to custom enhancements:
be-enhanced be-hiviors provide the ability to apply multiple cross-cutting enhancements to a single element. Sometimes, though, we need to apply them in a particular order.
be-promising provides this capability.
<input be-promising='{
"be":[ "typed", "clonable", "delible"]
}'>
Idea influenced by this discussion.
For this to work, be-decorated adopts a convention of using property "resolved" / event "resolved" to indicate when it has "done its thing", whatever that is.
<input be-promising='{
"be":[ "typed",
{
"clonable": {
"clonableSettings": "..."
},
},
{
"delible": {
"delibleSettings": "..."
}
}
]
}'>
Editing JSON-in-html can be rather error prone. A VS Code extension is available to help with that, and is compatible with web versions of VSCode.
And in practice, it is also quite ergonomic to edit these declarative web components in a *.mjs file that executes in node as the file changes, and compiles to an html file via the may-it-be compiler. This allows the attributes to be editable with JS-like syntax. Typescript 4.6 supports compiling mts to mjs files, which then allows typing of the attributes.
<label for=url>Enter Url</label>
<input id=url be-promising='{
"be": [{
"committed": "to-change"
}]
}'>
<button id=to-change>Search</button>
We can specify prerequisites for inner content enhancements to finish first before scheduling the tasks set in the "be" property:
<div be-promising='{
"waitForInnerEnhancementsToResolve": ["committed", "typed", "clonable"]
}'>
<input be-committed>
</div>
<input be-promising='{
"be":[ "typed", {
"clonable": {
"clonableSettings": "..."
},
"delible": {
"delibleSettings": "..."
}
}]
}'>
This would "resolve" the "be-typed" enhancement first, then launch be-clonable and be-delible.
One problem I've been struggling with is how to take DOM in the live DOM tree, and (declaratively) define a web component out of it. The three fundamental questions to grapple with:
- When to take the "snapshot" of the dom, and turn it into a template.
- What content it is safe to remove from that template in order to optimize the clone.
- How to capture the needed element enhancements when some of those enhancements are only applicable to hydrating from server-rendered content.
be-promising leaves behind a "breadcrumb" for server-rendered HTML, using guid's. Used by be-definitive [TODO].
Any web server than can serve static files will do, but...
- Install git.
- Do a git clone or a git fork of repository https://github.com/bahrus/be-promising
- Install node.js
- Open command window to folder where you cloned this repo.
-
npm install
-
npm run serve
- Open http://localhost:3030/demo in a modern browser.
<script type=module crossorigin=anonymous>
import 'https://esm.run/be-promising';
</script>
import 'be-promising/be-promising.js';