uhm/README.md

102 lines
3.0 KiB
Markdown
Raw Normal View History

2025-05-14 21:11:10 +00:00
# Uhm
2024-05-05 00:34:27 +00:00
2024-05-05 14:27:14 +00:00
> Minimal JavaScript UI Builder
2024-05-05 00:34:27 +00:00
2025-05-14 21:11:10 +00:00
Uhm, is 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-06 01:22:15 +00:00
2025-05-14 21:11:10 +00:00
Uhm, because you should think about, ah, NOT using it.
2024-05-05 00:34:27 +00:00
## Features
- Real DOM
- [Non-destructive (re)Rendering](https://github.com/bryhoyt/emerj)
2025-06-01 06:57:47 +00:00
- Supports tagged `html` syntax via [xhtm](https://github.com/dy/xhtm)
2024-05-05 00:34:27 +00:00
- No Build System
- No Over Engineering
2025-05-31 05:37:54 +00:00
- ~6kb minified / ~3kb gzip
> NOTE: experimenting with different builds, sizes may vary
2024-05-05 00:34:27 +00:00
2024-05-22 17:31:20 +00:00
## Install
Via JSDelivr CDN
```js
2025-05-14 21:11:10 +00:00
import {app,h} from "https://cdn.jsdelivr.net/gh/n2geoff/uhm/dist/uhm.min.js";
2024-05-22 17:31:20 +00:00
```
2024-05-05 00:34:27 +00:00
## Overview
2025-05-31 05:37:54 +00:00
**Uhm** only has 3 exported functions, `app()`, `h()` and `html`, and the later is optional.
2024-05-05 00:34:27 +00:00
2025-06-01 06:57:47 +00:00
### app(mount, {opts})
2024-05-05 00:34:27 +00:00
2025-06-01 06:57:47 +00:00
The `app()` builder function takes two arguments, the `mount` point as a selector or element, and the `opts` object made of:
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 |
| --------- | -------------------------- | ----------------------------------------------------------- |
2025-05-14 21:11:10 +00:00
| `state` | `{}` | initial data state |
| `actions` | `{key: (state) => {}}` | function object passed to view |
2024-05-05 14:27:14 +00:00
| `view` | `(state, actions) => null` | function that takes state and actions and returns valid dom |
2025-06-01 06:57:47 +00:00
2024-05-05 14:27:14 +00:00
#### Output:
2024-05-22 17:11:40 +00:00
Interface with internal state for utility expansion
2024-05-22 16:34:59 +00:00
2024-05-05 19:05:16 +00:00
| Property | Description |
| --------------- | --------------------------------------------- |
2024-05-22 17:11:40 +00:00
| `state` | internal state object |
| `update()` | function to render dom state |
2024-05-05 14:27:14 +00:00
2025-05-14 21:11:10 +00:00
> !IMPORTANT: long running operations require manual `update()` called
2025-05-31 05:37:54 +00:00
### h(tag, attrs, [...children])
2024-05-05 14:27:14 +00:00
2025-05-31 05:37:54 +00:00
The `h()` is a hypertext build utility that provides *a* way to build out your `view` DOM, but you can build your `view` using `html` or even `jsx`, really any method you like as long as it returns valid DOM.
2024-05-05 14:27:14 +00:00
2025-06-01 06:57:47 +00:00
```js
return h("h3", ${greeting});
```
### html
Instead of returning hypertext to build your dom, you can use regular html
```js
return html`<h3>Hello ${greeting}</h3>`;
```
2024-05-05 14:27:14 +00:00
## Example
2024-05-05 00:34:27 +00:00
```html
2025-06-01 06:57:47 +00:00
<div id="app"></div>
2024-05-05 00:34:27 +00:00
<script type="module">
2025-05-31 05:37:54 +00:00
import {app, h} from "./uhm.min.js";
2024-05-05 00:34:27 +00:00
2025-06-01 06:57:47 +00:00
const myapp = app("#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"}, [
2025-06-01 06:57:47 +00:00
h("h1", "Uhm, Hello"),
2024-05-05 00:34:27 +00:00
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
2024-05-22 15:06:33 +00:00
### TODO
- Rethink State Management, might be ok