matthewp / raj-element

Custom elements from raj programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

raj-element

Create custom elements from Raj programs.

import mapElement from './node_modules/raj-element/el.js';

const program = {
  init: [{
    count: 0 // An integer to count
  }],
  update (message, state) {
    let count = state.count + 1;
    return [{count}]; // Increment the state
  },
  view ({count}, dispatch, root) {
    // First render, probably use a vdom library instead.
    if(!root.firstChild) {
      root.innerHTML = `
        <h1>
          Count:
          <span id="count">0</span>
        </h1>
        <button type="button">Increment</button>
      `;

      root.querySelector('button').onclick = dispatch;
    }

    root.querySelector('#count').textContent = count;
  }
};

const Element = mapElement(program);

customElements.define('my-element', Element);

License

BSD 2 Clause

About

Custom elements from raj programs


Languages

Language:JavaScript 64.1%Language:HTML 29.8%Language:Makefile 6.2%