# osagai

> A tiny library for creating WebComponents in a Functional way

Latest version **0.3.5** (published 2019-11-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install osagai
pnpm add osagai
yarn add osagai
bun add osagai
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2019-11-10 |
| First published | 2018-11-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 99.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 53 |
| Author | Henrique Limas |
| Maintainers | henriquelimas |
| Keywords | osagai, webcomponents, functional-programming |

## Links

- npm: https://www.npmjs.com/package/osagai
- Repository: https://github.com/HenriqueLimas/osagai
- Homepage: https://henriquelimas.github.io/osagai/
- Issues: https://github.com/HenriqueLimas/osagai/issues
- npm.io page: https://npm.io/package/osagai

## Recent versions

- 0.3.5 (latest) — 2019-11-10
- 0.3.4 — 2019-11-10
- 0.3.3 — 2019-11-02
- 0.3.2 — 2019-03-08
- 0.3.1 — 2019-03-08
- 0.3.0 — 2019-01-26
- 0.2.2 — 2019-01-06
- 0.2.1 — 2019-01-02
- 0.2.0 — 2018-12-30
- 0.1.1 — 2018-12-21
- 0.1.0 — 2018-12-21
- 0.0.10 — 2018-12-05
- 0.0.9 — 2018-12-04
- 0.0.8 — 2018-12-03
- 0.0.7 — 2018-12-02
- … 6 more at https://npm.io/package/osagai/versions

## README

# Osagai 🀄️ [![Build Status](https://travis-ci.com/HenriqueLimas/osagai.svg?branch=master)](https://travis-ci.com/HenriqueLimas/osagai)

A tiny library in a functional and browser way.

## Why?

Creating WebComponent shouldn't be limited to extending `class`es. It should be easy to create and in a functional way.
It should be able to be framework-agnostic and be reused in different libraries. Updating components should be fast and it should
use native solutions without VirtualDOM and data binding magics. It should not need build processes for compiling non
native solution (JSX) and take advantage in what the language has. ([Template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals))

- [Documentation](https://osagai.js.org/docs/)

## Install

You can get it on npm.

```
npm install osagai
```

Or import from unpkg

```js
import { define } from "https://unpkg.com/osagai/osagai.mjs";
import { on } from "https://unpkg.com/osagai/events.mjs";
```

## Define a Web component

Osagai comes with a function called `define` that defines a new custom element that you can use in your application.
`define` receives the name of the custom element (it must contain a hyphen) and the Osagai component.
The Osagai component is a function that returns a Template with a string representing the layout of the web component.

```javascript
import { define } from 'osagai'

function MyComponent() {
	return () => `<h1>Hi 👋!</h1>`
}

define('waving-hand', MyComponent)

```

Now, you just need to use your new custom element in your application.

```html
<waving-hand></waving-hand>
```

## Example

```html
<!DOCTYPE html>
<html lang="en">
  <title>Osagai demo</title>

  <x-items></x-items>

  <script type="module">
    import { define } from "https://unpkg.com/osagai/osagai.mjs";
    import { on } from "https://unpkg.com/osagai/events.mjs";
    import { update } from "https://unpkg.com/osagai/dom.mjs";

    function Items({ element, query }) {
      const initialState = {
        items: []
      };

      on("click", query(".btn"), () => {
        update(element, ({ items } = initialState) => {
          items.push({
            name: `Item nr ${items.length + 1}`
          });

          return {
            items
          };
        });
      });

      return ({ items } = initialState) => `
        <div>
          <button class="btn">Add item</button>
          <ul class="list">
            ${items.map(item => `<li>${item.name}</li>`).join("")}
          </ul>
        </div>`;
    }

    define("x-items", Items);
  </script>
</html>
```

- Hacker News PWA example: https://github.com/HenriqueLimas/osagai-hn

## Project status

Osagai is still under development and it needs some feedback from the community. If you want to collaborate, please
add an [issue](https://github.com/HenriqueLimas/osagai/issues) or [PR](https://github.com/HenriqueLimas/osagai/pulls) with
your suggestions or concerns.

---
_Source: https://npm.io/package/osagai · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
