An open API service indexing awesome lists of open source software.

https://github.com/clebert/snugjs

Create reactive web components using generator functions.
https://github.com/clebert/snugjs

Last synced: about 1 year ago
JSON representation

Create reactive web components using generator functions.

Awesome Lists containing this project

README

          

# snugjs

> Create reactive web components using generator functions.

## Installation

```
npm install snugjs
```

## TodoMVC

A work-in-progress implementation of [TodoMVC](http://todomvc.com) using
`snugjs` and [`@snugjs/html`](https://github.com/clebert/snugjs-html) can be
found [here](https://github.com/clebert/snugjs-todomvc).

## `` Element Factory

```jsx
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(
-,
+,
{count},
);

yield;
}
},
);
```

```jsx
document.body.appendChild();
```

```html



```