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(slug: string [, state: object]) : object
Creates an custom, scoped HTML tag. Requires a slug, which is a CSS selector as a string. An optional second argument may be passed for seeding the initial state.
It will return an object with the slug 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. An event type, a css selector, and a handler. No selector will listen on the tag's root. Returns a function to remove the listener when invoked.
get() : object
Returns the current state.
set(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
restore() : promise(state)
Recovers the previous state allowing for persisting data across page refreshes. Called automatically when a new tag is initialized. Returns a promise with the tag's state.
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.