`deka-dom-el` — Introduction

Introducing a library.

The library tries to provide pure JavaScript tool(s) to create reactive interfaces using …

# Event-driven programming (3 parts separation ≡ 3PS)

Let's introduce the basic principle on which the library is built. We'll use the JavaScript listener as a starting point.

// pseudo code! const onchage= event=> console.log("Reacting to the:", event); // A input.addEventListener("change", onchange); // B input.dispatchEvent(new Event("change")); // C

As we can see, in the code at location “A” we define how to react when the function is called with any event as an argument. At that moment, we don't care who/why/how the function was called. Similarly, at point “B”, we reference to a function to be called on the event without caring what the function will do at that time. Finally, at point “C”, we tell the application that a change has occurred, in the input, and we don't care if/how someone is listening for the event.

import { el } from "./esm-with-signals.js"; import { S } from "./esm-with-signals.js"; const clicks= S(0); // A document.body.append( el().append( el("p", S(()=> "Hello World "+"🎉".repeat(clicks()) // B )), el("button", { type: "button", onclick: ()=> clicks(clicks()+1), // C textContent: "Fire", }) ) );

The library introduces a new “type” of variable/constant called signal allowing us to to use introduced 3PS pattern in our applications. As you can see it in the example above.

Also please notice that there is very similar 3PS pattern used for separate creation of UI and business logic.

The 3PS is very simplified definition of the pattern. There are more deep/academic definitions more precisely describe usage in specific situations, see for example MVVM or MVC.

# Organization of the documentation