Home

Awesome

<em>µ</em>html-intents

Build Status Coverage Status CSP strict

<sup>Social Media Photo by Markus Winkler on Unsplash</sup>

An utility to bring hyperHTML intents into µhtml.

Live Demo

import {render, html} from 'uhtml';
import {define, intent} from 'uhtml-intents';

// a basic i18n example: key => {lang1, langX}
const i18n = {
  greetings: {
    it: 'Ciao!',
    en: 'Hello!'
  }
};

// the user chosen language
let lang = 'it';

// define a basic i18n intent via a key name so that
// when intent({i18n: 'greetings'}) is used, the function
// will receive 'greetings' as argument: define(key, fn)
define('i18n', key => {
  // so that the right translation can be offered
  return i18n[key][lang];
});

render(document.body, html`
  <div>
    ${intent({i18n: 'greetings'})}
  </div>
`);

In Details

const myIntent = Symbol('my-intent');

define(myIntent, doMyThing);

render(document.body, html`
  <div>
    ${intent({[myIntent]: data})}
  </div>
`);