Tag provides a unified approach forrendering,
and only those four things.
Plainly, Tag is a trifecta of
designed to build expressive web applications.
Hello World is a common program to write when first learning something new. The code below imports tag.js, creates a custom tag, and sets to be the content to 'Hello World!'
import tag from 'https://thelanding.page/tag/tag.js'
tag('hello-world').html(() => 'Hello World!')
Tip! View the source of the example page to see <hello-world> in action!
tag(selector: string [, state: object]) : object
Creates an custom, scoped HTML tag. Requires a selector: a CSS selector. An optional second argument may be passed for seeding the initial state.
It will return an object with the selector as an attribute and the following namespaced functions.
Toggle Visibility of returned object properties.
Expects a function that returns HTML as a string to be rendered into the provided target. A falsey return will leave the target node untouched. This function will be invoked whenever state changes.
Expects a CSS stylesheet as a string. The ampersand (&) symbol may be used to scope rulesets.
on(eventType, selector, function(event)) : function
An event delegator that expects three arguments. A css selector, and a handler. No selector will listen on the tag's root. Returns a function to remove the listener when invoked.
read() : object
Returns the current state.
write(payload [, function(state, payload)])
Merges the payload into the current state. An optional second argument for managing the state update may be provided. That function will be called with the current state and the payload. It expects the reconciled, complete state to be returned
ready(function()) : void
The provided callback will be invoked when the tag is ready: once data has been restored from the database.
Dependencies: There is one third-party dependency, diffHTML.
Browser Support: The tail feature set for this application is ES Modules, which is supported by all modern browsers. For an entertaining summary, please refer to Making Future Interfaces: ES Modules.