Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaandrle/deka-dom-el
A library expanding the capabilities of the native DOM API with the aim of offering the possibility of writing reactive UI templates/components declaratively directly in JavaScript.
https://github.com/jaandrle/deka-dom-el
client-side-rendering declarative declarative-programming declarative-ui dom functional-programming javascript reactive reactive-programming rendering server-side-rendering signals signals-library typescript ui ui-components vanilla-javascript vanilla-js webcomponents
Last synced: 4 days ago
JSON representation
A library expanding the capabilities of the native DOM API with the aim of offering the possibility of writing reactive UI templates/components declaratively directly in JavaScript.
- Host: GitHub
- URL: https://github.com/jaandrle/deka-dom-el
- Owner: jaandrle
- License: mit
- Created: 2023-08-22T14:36:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-13T18:38:12.000Z (11 days ago)
- Last Synced: 2024-12-17T00:28:50.664Z (8 days ago)
- Topics: client-side-rendering, declarative, declarative-programming, declarative-ui, dom, functional-programming, javascript, reactive, reactive-programming, rendering, server-side-rendering, signals, signals-library, typescript, ui, ui-components, vanilla-javascript, vanilla-js, webcomponents
- Language: JavaScript
- Homepage: https://jaandrle.github.io/deka-dom-el/
- Size: 1.16 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**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)***Vanilla for flavouring β a full-fledged feast for large projects***
*β¦use simple DOM API by default and library tools and logic when you need them*
```javascript
document.body.append(
el(HelloWorldComponent, { initial: "π" })
);
/** @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 has only two options with {@link Emoji}
const onChange= on("change", event=> emoji(event.target.value));return el().append(
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)),
),
el("select", null, onChange).append(
el(OptionComponent, "π", isSelected),//OR { textContent: "π" }
el(OptionComponent, "π", isSelected),//OR { textContent: "π" }
)
);
}
function OptionComponent({ textContent }){
return el("option", { value: textContent, textContent })
}
```
# Deka DOM Elements
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).## Inspiration and suggested alternatives
- 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)
- [hyperhype/hyperscript: Create HyperText with JavaScript.](https://github.com/hyperhype/hyperscript)
- [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))
- [potch/signals: a small reactive signals library](https://github.com/potch/signals)## Why anΒ another one?
This library falls somewhere between van/hyperscript and [solid-js](https://github.com/solidjs/solid) in terms of size,
complexity, and usability.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.As a result, any βinternalβ function (`assign`, `classListDeclarative`, `on`, `dispatchEvent`, β¦, `S`, β¦)
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)
- [x] Optional use of *signals* with the ability to register *your own signals/observables implementation*
- [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## First steps
- [**Guide**](https://jaandrle.github.io/deka-dom-el)
- Documentation
- Installation
- npm
- [dist/](dist/) (`https://cdn.jsdelivr.net/gh/jaandrle/deka-dom-el/dist/`β¦)## Signals
- [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)
- [Observer pattern - Wikipedia](https://en.wikipedia.org/wiki/Observer_pattern)