um/README.md

68 lines
2.3 KiB
Markdown
Raw Normal View History

2024-05-05 00:34:27 +00:00
# Tagged
2024-05-05 14:27:14 +00:00
> Minimal JavaScript UI Builder
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
An experimental composable UI builder that takes ideas from early [hyperapp](https://github.com/jorgebucaran/hyperapp) design, but does not stick to strict Elm Architecture.
2024-05-05 00:34:27 +00:00
## Features
- No Virtual Dom
- No Build System
- No Over Engineering
2024-05-05 13:07:17 +00:00
- ~1kb minified
- Totally INEFFICIENT rendering (at scale)
2024-05-05 00:34:27 +00:00
## Overview
2024-05-05 14:27:14 +00:00
The library only has 2 functions, `app()` and `h()`, and the later is optional.
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
### app({opts})
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
The `app()` is the builder function and takes an `opts` object:
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
#### Input:
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
| Property | Default | Description |
| --------- | -------------------------- | ----------------------------------------------------------- |
| `state` | `{}` | initial data state |
| `actions` | `{}` | function object passed to view |
| `view` | `(state, actions) => null` | function that takes state and actions and returns valid dom |
| `mount` | "body" | valid query selector as mounting point |
#### Output:
2024-05-05 19:05:16 +00:00
| Property | Description |
| --------------- | --------------------------------------------- |
| `state([data])` | state function to get or update internal data |
2024-05-05 14:27:14 +00:00
### h(tag, [...args])
The `h()` is an **optional** hypertext build utility that weighs in around **~250b** and is provided as *a* way to build out your view markdown, but you can build your view using any method you like as long as it returns valid dom.
## Example
2024-05-05 00:34:27 +00:00
```html
<script type="module">
2024-05-05 13:07:17 +00:00
import {app, h} from "./tagged.min.js";
2024-05-05 00:34:27 +00:00
const myapp = app({
state: {name: "[Your Name Here]", job: "Developer"},
view(state, actions) {
2024-05-05 00:34:27 +00:00
return h("main", [
h("strong", `Greeting from ${state.name}`),
h("div", `Your local ${state.job}`),
h("div", {id: "test"}, [
h("h1", "Hello Tagged"),
h("p", 21),
h("hr")
])
]);
}
2024-05-05 14:27:14 +00:00
});
2024-05-05 00:34:27 +00:00
</script>
```
2024-05-05 13:07:17 +00:00
## Notes
2024-05-05 00:34:27 +00:00
2024-05-05 19:05:16 +00:00
> WORK-IN-PROGRESS