Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/herber/xou

β³πŸš€ A rocket fast library for building component based UIs.
https://github.com/herber/xou

dom dom-diffing tagged-template-literals ui ui-components

Last synced: 4 months ago
JSON representation

β³πŸš€ A rocket fast library for building component based UIs.

Awesome Lists containing this project

README

        




A tiny library for building simple component based UIs with template literals. It offers the same features as yo-yo but is a bit smaller.


Xou is powered by hyperx and nanomorph.

## Features

- Tagged template literals
- Diffing on real dom nodes
- Tiny at just [4kb](https://bundlephobia.com/result?p=xou)

## Install

```
$ npm install xou
```

## Usage

```js
const xou = require('xou');

const time = xou`Time: ${ (new Date()).toUTCString() }`;

document.body.appendChild(time);

setInterval(() => {
Β const newTime = xou`Time: ${ (new Date()).toUTCString() }`;
xou.update(time, newTime);
}, 1000);
```

## API

### xou\`\`

A tagged template literal returning dom nodes

#### Example

```js
const node = xou`


Hello from xou


Xou on github


`;

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

### xou.update(oldNode, newNode)

`xou.update` diffs an old and a new dom node. The changes will be applied to `oldNode`.

#### Example

```js
const hello = xou`Hello! { update(); } }>Update`;

const update = () => {
const hi = xou`Hi!`;
xou.update(hello, hi);
}

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

## Other Modules

This whole thing is powered by [`hyperx`](https://github.com/choojs/hyperx) and [`nanomorph`](https://github.com/choojs/nanomorph) - two tiny but really great packages.

This module is heavily inspired by [`yo-yo`](https://github.com/maxogden/yo-yo) - `xou` is basically a smaller alternative to `yo-yo`.

Xou pairs really well with [`vxv`](https://github.com/herber/vxv) for styles and [`nation`](https://github.com/herber/nation) for state management.

## License

MIT Β© [Tobias Herber](http://tobihrbr.com)