2024-12-13 15:04:52 +01:00
|
|
|
|
**WIP** (the experimentation phase)
|
|
|
|
|
| [source code on GitHub](https://github.com/jaandrle/deka-dom-el)
|
|
|
|
|
| [*mirrored* on Gitea](https://gitea.jaandrle.cz/jaandrle/deka-dom-el)
|
2023-08-22 16:56:00 +02:00
|
|
|
|
|
2023-11-16 21:18:48 +01:00
|
|
|
|
***Vanilla for flavouring — a full-fledged feast for large projects***
|
2023-11-16 20:48:58 +01:00
|
|
|
|
|
2023-11-07 21:58:48 +01:00
|
|
|
|
*…use simple DOM API by default and library tools and logic when you need them*
|
2023-08-23 15:37:32 +02:00
|
|
|
|
|
2024-12-13 15:04:52 +01:00
|
|
|
|
```javascript
|
2023-08-23 15:37:32 +02:00
|
|
|
|
document.body.append(
|
2024-12-13 15:04:52 +01:00
|
|
|
|
el(HelloWorldComponent, { initial: "🚀" })
|
2023-08-23 15:37:32 +02:00
|
|
|
|
);
|
2024-12-13 15:04:52 +01:00
|
|
|
|
/** @typedef {"🎉" | "🚀"} Emoji */
|
|
|
|
|
/** @param {{ initial: Emoji }} attrs */
|
|
|
|
|
function HelloWorldComponent({ initial }){
|
|
|
|
|
const clicks= S(0);
|
|
|
|
|
const emoji= S(initial);
|
|
|
|
|
/** @param {HTMLOptionElement} el */
|
|
|
|
|
const isSelected= el=> (el.selected= el.value===initial);
|
|
|
|
|
// @ts-expect-error 2339: The <select> has only two options with {@link Emoji}
|
|
|
|
|
const onChange= on("change", event=> emoji(event.target.value));
|
|
|
|
|
|
2023-11-16 20:48:58 +01:00
|
|
|
|
return el().append(
|
2024-12-13 15:04:52 +01:00
|
|
|
|
el("p", {
|
|
|
|
|
textContent: S(() => `Hello World ${emoji().repeat(clicks())}`),
|
|
|
|
|
className: "example",
|
|
|
|
|
ariaLive: "polite", //OR ariaset: { live: "polite" },
|
|
|
|
|
dataset: { example: "Example" }, //OR dataExample: "Example",
|
|
|
|
|
}),
|
|
|
|
|
el("button",
|
|
|
|
|
{ textContent: "Fire", type: "button" },
|
|
|
|
|
on("click", ()=> clicks(clicks() + 1)),
|
|
|
|
|
on("keyup", ()=> clicks(clicks() - 2)),
|
2023-11-16 20:48:58 +01:00
|
|
|
|
),
|
2024-12-13 15:04:52 +01:00
|
|
|
|
el("select", null, onChange).append(
|
|
|
|
|
el(OptionComponent, "🎉", isSelected),//OR { textContent: "🎉" }
|
|
|
|
|
el(OptionComponent, "🚀", isSelected),//OR { textContent: "🚀" }
|
|
|
|
|
)
|
2023-11-16 20:48:58 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2024-12-13 15:04:52 +01:00
|
|
|
|
function OptionComponent({ textContent }){
|
|
|
|
|
return el("option", { value: textContent, textContent })
|
|
|
|
|
}
|
2023-08-23 15:37:32 +02:00
|
|
|
|
```
|
2023-11-07 21:58:48 +01:00
|
|
|
|
# Deka DOM Elements
|
2024-12-13 15:04:52 +01:00
|
|
|
|
Creating reactive elements, components and Web components using [IDL](https://developer.mozilla.org/en-US/docs/
|
|
|
|
|
Glossary/IDL)/JavaScript DOM API and [**signals/observables**](#signals).
|
2023-11-07 21:58:48 +01:00
|
|
|
|
|
|
|
|
|
## Inspiration and suggested alternatives
|
2024-12-13 15:04:52 +01:00
|
|
|
|
- my previous library (mostly used internaly): [jaandrle/dollar_dom_component: Functional DOM components without
|
|
|
|
|
JSX and virtual DOM.](https://github.com/jaandrle/dollar_dom_component)
|
|
|
|
|
- [vanjs-org/van: 🍦 VanJS: World's smallest reactive UI framework. Incredibly Powerful, Insanely Small -
|
|
|
|
|
Everyone can build a useful UI app in an hour.](https://github.com/vanjs-org/van)
|
2023-11-07 21:58:48 +01:00
|
|
|
|
- [hyperhype/hyperscript: Create HyperText with JavaScript.](https://github.com/hyperhype/hyperscript)
|
2024-12-13 15:04:52 +01:00
|
|
|
|
- [adamhaile/S: S.js - Simple, Clean, Fast Reactive Programming in Javascript](https://github.com/adamhaile/S)
|
|
|
|
|
([adamhaile/surplus: High performance JSX web views for S.js applications](https://github.com/adamhaile/surplus))
|
2023-11-07 21:58:48 +01:00
|
|
|
|
- [potch/signals: a small reactive signals library](https://github.com/potch/signals)
|
|
|
|
|
|
|
|
|
|
## Why an another one?
|
2024-12-13 15:04:52 +01:00
|
|
|
|
This library falls somewhere between van/hyperscript and [solid-js](https://github.com/solidjs/solid) in terms of size,
|
|
|
|
|
complexity, and usability.
|
2023-11-16 20:48:58 +01:00
|
|
|
|
|
|
|
|
|
Another goal is to proceed in the best spirit of functional programming. This involves starting with
|
|
|
|
|
pure JavaScript (DOM API) and gradually adding auxiliary functions, ranging from “minor” improvements
|
|
|
|
|
to the capability of writing complete declarative reactive UI templates.
|
|
|
|
|
|
2024-05-22 21:43:49 +02:00
|
|
|
|
As a result, any “internal” function (`assign`, `classListDeclarative`, `on`, `dispatchEvent`, …, `S`, …)
|
2023-11-16 20:48:58 +01:00
|
|
|
|
can be used independently, although they are primarily designed for use in combination. This can also,
|
|
|
|
|
hopefully, help in integrating the library into existing projects.
|
|
|
|
|
|
|
|
|
|
To balance these requirements, numerous compromises have been made. To summarize:
|
|
|
|
|
- [ ] Library size: 10–15kB minified (the original goal was a maximum of 10kB)
|
2024-05-22 21:43:49 +02:00
|
|
|
|
- [x] Optional use of *signals* with the ability to register *your own signals/observables implementation*
|
2023-11-16 20:48:58 +01:00
|
|
|
|
- [x] *No build step required*
|
|
|
|
|
- [x] Preference for a *declarative/functional* approach
|
|
|
|
|
- [x] Focus on zero/minimal dependencies
|
|
|
|
|
- [ ] Support for/enhancement of custom elements (web components)
|
|
|
|
|
- [x] Support for SSR ([jsdom](https://github.com/jsdom/jsdom))
|
|
|
|
|
- [ ] WIP providing types
|
2023-11-07 21:58:48 +01:00
|
|
|
|
|
|
|
|
|
## First steps
|
|
|
|
|
- [**Guide**](https://jaandrle.github.io/deka-dom-el)
|
|
|
|
|
- Documentation
|
2023-11-16 21:18:48 +01:00
|
|
|
|
- Installation
|
2023-11-07 21:58:48 +01:00
|
|
|
|
- npm
|
|
|
|
|
- [dist/](dist/) (`https://cdn.jsdelivr.net/gh/jaandrle/deka-dom-el/dist/`…)
|
2024-05-22 21:43:49 +02:00
|
|
|
|
|
|
|
|
|
## Signals
|
2024-12-13 15:04:52 +01:00
|
|
|
|
- [Signals — whats going on behind the scenes | by Ryan Hoffnan | ITNEXT](https://itnext.io/
|
|
|
|
|
signals-whats-going-on-behind-the-scenes-ec858589ea63)
|
|
|
|
|
- [The Evolution of Signals in JavaScript - DEV Community](https://dev.to/this-is-learning/the-evolution-of-signals-in-
|
|
|
|
|
javascript-8ob)
|
|
|
|
|
- there is also [tc39/proposal-signals: A proposal to add signals to JavaScript.](https://github.com/tc39/proposal-
|
|
|
|
|
signals)
|
2024-05-22 21:43:49 +02:00
|
|
|
|
- [Observer pattern - Wikipedia](https://en.wikipedia.org/wiki/Observer_pattern)
|