+ The element helper automates many utility features that
+ often have to be added to every new custom element, like dispatching
+ to different handler methods depending on the name of a changed attribute
+ or adding getters and setters for these attributes.
+
+
+
+
Basic Usage
+
+
+ element(class MyElement extends HTMLElement {
+ constructor() {
+ super()
+ console.log("An element walks into a bar...")
+ }
+ })
+
+
+
Features
+
+
+
Attributes
+
+ The static attributes property, when present,
+ is used to automatically add the static observedAttributes
+ property for the custom element API, as well as define getters and setters
+ for the listed attributes.
+
+ A pair of filters can be given to modify the value after getting or before
+ setting it. This can be used to convert between the string values that
+ attributes restrict us to and a more sensible representation as well as
+ some validation (attributes can be changed externally, after all).
+
+ Object keys in camelCase will be converted to kebab-case before being
+ used as attribute names in the auto-generated observedAttributes.
+
+ The rules are:
+
+
Any truthy value registers the attribute with getter and setter
+
If the value has a get property, it will be incorporated as a filter into the getter.
+
If the value has a set property, it will be incorporated as a filter into the setter.
+
Unless this value is false no setter will be added (read only attribute).
+
+ The attributeChangedCallback method is added automatically to the class.
+ This auto-generated callback will first look up a ${attributeName}Changed
+ method and call it, if found, with the old and new values as arguments.
+ Then it will look for a changed method and call it with the same arguments
+ as attributeChangedCallback normally receives.
+
+ Attribute names will be converted from camelCase to kebab-case when needed before
+ being used to form a method name to look up.
+ Changing an attribute foo-bar will look for a fooBarChanged method.
+
+ Certain methods, like re-rendering the content of a component
+ should often happen in response to events that can happen repeatedly,
+ or in response to many different events that can all happen at once.
+
+ To avoid having to repeatedly add complicated checks to handle these
+ event bursts, element introduces the concept of dollar-methods.
+
+ Any method with a name starting with $ will automatically
+ have a sibling-method defined, with the dollar removed. Each time this
+ auto-generated method is called, its argument list will be pushed to an array
+ and a call of the original dollar-method will be scheduled as a micro-task.
+
+ The original method will then be called with the argument-lists of the individual
+ calls to its dollar-less counterpart all at once.
+
+ It is of course still possible to manually call the dollar-method when
+ immediate execution is wanted.
+
+
+
+ Note how in the following example, all three change methods would be called
+ in rapid succession if the browser applies the custom element class to an element
+ it found on the page with all three attributes foo, bar
+ and baz defined.
+
+ Here, this.render() will not instantly re-render the whole component
+ but instead schedule the re-render in a micro-task, potentially avoiding lots of
+ repeated work.
+
+
+
diff --git a/page/style.css b/page/style.css
index 4ef675d..b102ab9 100644
--- a/page/style.css
+++ b/page/style.css
@@ -41,6 +41,11 @@ h2 {
border-bottom: .1em solid var(--color-ac);
}
+h3::before {
+ content: "\2023" ' ';
+ color: var(--color-ac);
+}
+
em {
font-style: normal;
font-weight: bold;
diff --git a/readme.md b/readme.md
index fa04e60..079980b 100644
--- a/readme.md
+++ b/readme.md
@@ -13,6 +13,11 @@ So what does it all do?
an "improved" version of the builtin HTMLElement that's hopefully a lot easier
to build actual things with. It's really just another utility layer.
+## Element
+
+the second iteration of improved `HTMLElement` but this time in a function to
+support inheriting from other classes for extending builtin elements.
+
## CSS
Generate CSS from JS objects. Yes, you can generate CSS from JSON now. Or from