closures

0.7.11 • Public • Published

closures

This is a fork of petit-dom by Yassine Elouafi, but with object components replaced with "closure components" inspired by Mithril.js.

const { h, app, onRemove } = closures;

function App() {
  return (
    h('div.monospace',
      h('h1', 'A simple app'),
      h(Counter, { initialCount: 0 })
    )
  );
}

// simple components
function Double({ count }) {
  return h('h2', count * 2);
}

// stateful components
function Counter({ initialCount }) {
  let count = initialCount;

  onRemove(() => {
    console.log('Unmounted Counter');
  });

  return () => [
    h('h2', count),
    h('h3', 'doubled:'),
    h(Double, { count }),
    h('button', { onclick: () => count += 1 }, 'increment')
  ];
}

app(h(App), document.body);

Install

npm install closures

Examples

Counter

Todo List

Async

Readme

Keywords

Package Sidebar

Install

npm i closures

Weekly Downloads

16

Version

0.7.11

License

MIT

Unpacked Size

62.9 kB

Total Files

6

Last publish

Collaborators

  • kevinfiol