Jan Andrle
f1983dcd38
- new reactive element content can be empty (or contains DocumentFragment) - better WC observed attributes handling |
||
---|---|---|
bs | ||
dist | ||
docs | ||
docs_src | ||
examples | ||
src | ||
.gitignore | ||
index-with-observables.d.ts | ||
index-with-observables.js | ||
index.d.ts | ||
index.js | ||
jsdom.d.ts | ||
jsdom.js | ||
LICENSE | ||
observables.d.ts | ||
observables.js | ||
package-lock.json | ||
package.json | ||
README.md | ||
tsconfig.json |
WIP (the experimentation phase) | source code on GitHub | mirrored on Gitea
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
document.body.append(
el("h1", "Hello World 👋"),
el("p", "See some syntax examples here:"),
el("ul").append(
el("li").append(
el("a", { textContent: "Link to the library repo", title: "Deka DOM El — GitHub", href: "https://github.com/jaandrle/deka-dom-el" })
),
el("li").append(
"Use extended Vanilla JavaScript DOM/IDL API: ",
el("span", { textContent: "» this is a span with class=cN and data-a=A, data-b=B «", className: "cN", dataset: { a: "A", b: "B" } })
),
el("li").append(
el(component, { textContent: "A component", className: "example" }, on("change", console.log))
)
)
);
function component({ textContent, className }){
const value= O("onchange");
return el().append(
el("p", { textContent, className }),
el("p", { className: [ className, "second-line" ] }).append(
"…with reactivity: ", el("em", { style: { fontWeight: "bold" }, ariaset: { live: "polite" }, textContent: value }),
),
el("input", { type: "text", value: value() }, on("change", event=> value(event.target.value)))
);
}
Deka DOM Elements
Creating reactive elements, components and Web components using IDL/JavaScript DOM API and signals/observables (Signals — whats going on behind the scenes | by Ryan Hoffnan | ITNEXT, The Evolution of Signals in JavaScript - DEV Community or Observer pattern - Wikipedia).
Inspiration and suggested alternatives
- my previous library (mostly used internaly): jaandrle/dollar_dom_component: Functional DOM components without JSX and virtual DOM.
- vanjs-org/van: 🍦 VanJS: World's smallest reactive UI framework. Incredibly Powerful, Insanely Small - Everyone can build a useful UI app in an hour.
- hyperhype/hyperscript: Create HyperText with JavaScript.
- adamhaile/S: S.js - Simple, Clean, Fast Reactive Programming in Javascript (adamhaile/surplus: High performance JSX web views for S.js applications)
- potch/signals: a small reactive signals library
Why an another one?
This library falls somewhere between van/hyperscript and solid-js 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
, …, O
, …)
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)
- Optional use of observables with the ability to register your own signals/observables implementation
- No build step required
- Preference for a declarative/functional approach
- Focus on zero/minimal dependencies
- Support for/enhancement of custom elements (web components)
- Support for SSR (jsdom)
- WIP providing types