3.1.0 • Published 2 years ago

snugjs v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

snugjs

Create reactive web components using generator functions.

Installation

npm install snugjs

TodoMVC

A work-in-progress implementation of TodoMVC using snugjs and @snugjs/html can be found here.

<Counter /> Element Factory

import {createElement} from '@snugjs/html';
import {CustomElement, createElementRef} from 'snugjs';

export const Counter = CustomElement.define(
  `x-counter`,
  {initialCount: `number?`},
  function* ({next, signal}) {
    const decrementButton = createElementRef(`button`);
    const incrementButton = createElementRef(`button`);

    let count = this.props.initialCount ?? 0;

    decrementButton.element.addEventListener(
      `click`,
      () => {
        count -= 1;
        next();
      },
      {signal},
    );

    incrementButton.element.addEventListener(
      `click`,
      () => {
        count += 1;
        next();
      },
      {signal},
    );

    while (true) {
      this.replaceChildren(
        <button key={decrementButton.key}>-</button>,
        <button key={incrementButton.key}>+</button>,
        <b>{count}</b>,
      );

      yield;
    }
  },
);
document.body.appendChild(<Counter initialCount={42} />);
<html>
  <body>
    <x-counter initialCount="42"></x-counter>
  </body>
</html>
1.1.0

2 years ago

1.0.0

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago