0.7.11 • Published 1 year ago

closures v0.7.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

0.7.11

1 year ago

0.7.10

1 year ago

0.7.9

1 year ago

0.7.8

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.7.4

1 year ago

0.7.3

1 year ago

0.7.2

1 year ago

0.7.1

2 years ago