Skip to content

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.

License

Notifications You must be signed in to change notification settings

jaandrle/deka-dom-el

Repository files navigation

WIP (the experimentation phase) | source code on GitHub | mirrored on Gitea

Deka DOM Elements Logo

Deka DOM Elements (dd<el> or DDE)

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

// ๐ŸŒŸ Reactive component with clear separation of concerns
document.body.append(
	el(EmojiCounter, { initial: "๐Ÿš€" })
);

function EmojiCounter({ initial }) {
	// โœจ State - Define reactive data
	const count = S(0);
	const emoji = S(initial);

	/** @param {HTMLOptionElement} el */
	const isSelected= el=> (el.selected= el.value===initial);

	// ๐Ÿ”„ View - UI updates automatically when signals change
	return el().append(
		el("p", {
			className: "output",
			textContent: S(() =>
				`Hello World ${emoji.get().repeat(clicks.get())}`),
		}),

		// ๐ŸŽฎ Controls - Update state on events
		el("button", { textContent: "Add Emoji" },
			on("click", () => count.set(count.get() + 1))
		),

		el("select", null,
			on("change", e => emoji.set(e.target.value))
		).append(
			el(Option, "๐ŸŽ‰", isSelected),
			el(Option, "๐Ÿš€", isSelected),
			el(Option, "๐Ÿ’–", isSelected),
		)
	);
}
function Option({ textContent }){
	return el("option", { value: textContent, textContent });
}

Creating reactive elements, components, and Web Components using the native IDL/JavaScript DOM API enhanced with signals/observables.

Features at a Glance

  • โœ… No build step required โ€” use directly in browsers or Node.js
  • โ˜‘๏ธ Lightweight โ€” ~10-15kB minified (original goal 10kB) with zero/minimal dependencies
  • โœ… Declarative & functional approach for clean, maintainable code
  • โœ… Signals and events for reactive UI
  • โœ… Optional build-in signals with support for custom reactive implementations
  • โœ… Server-side rendering support via jsdom
  • โœ… TypeScript support (work in progress)
  • โ˜‘๏ธ Support for debugging with browser DevTools without extensions
  • โ˜‘๏ธ Enhanced Web Components support (work in progress)

Why Another Library?

This library bridges the gap between minimal solutions like van/hyperscript and more comprehensive frameworks like solid-js, offering a balanced trade-off between size, complexity, and usability.

Following functional programming principles, dd<el> starts with pure JavaScript (DOM API) and gradually adds auxiliary functions. These range from minor improvements to advanced features for building complete declarative reactive UI templates.

A key advantage: any internal function (assign, classListDeclarative, on, dispatchEvent, S, etc.) can be used independently while also working seamlessly together. This modular approach makes it easier to integrate the library into existing projects.

Getting Started

Installation

npm

# TBD
# npm install deka-dom-el

Direct Script

<script src="https://cdn.jsdelivr.net/gh/jaandrle/deka-dom-el/dist/iife-with-signals.min.js"></script>
<script type="module">
	const { el, S } = DDE;
</script>

Documentation

Understanding Signals

Signals are the reactive backbone of Deka DOM Elements:

Inspiration and Alternatives