choc

Lindt - Master Chocolatier

(If you want chocolates you can actually eat, the creations of the Lindt & Sprungli company are spectacular, and are what inspired the name of this module.)

Rather than building your chocolates yourself, call on a master chocolatier! This has overhead, of course, but can offer some hefty benefits. Replace all use of ‘choc’ with ‘lindt’, and of ‘set_content’ with ‘replace_content’, and our craftsmen will assemble chocolate to your exacting specifications.

Here’s how you make your own chocolate:

import {choc, set_content, on, DOM} from "https://rosuav.github.io/choc/factory.js";
const {FORM, INPUT, LABEL} = choc; //autoimport
set_content("body", FORM(
    LABEL(["Speak thy mind:", INPUT({name: "thought"})])
);

Here’s how you get a chocolatier to make it for you:

import {lindt, replace_content, on, DOM} from "https://rosuav.github.io/choc/factory.js";
const {FORM, INPUT, LABEL} = lindt; //autoimport
replace_content("body", FORM(
    LABEL(["Speak thy mind:", INPUT({name: "thought"})])
);

It’s that simple! Of course, there are a number of consequences. Here are the differences between choc/set_content and lindt/replace_content:

The key benefit of replace_content is that it will reuse existing DOM elements rather than construct new ones. This means less flicker, hopefully less CPU load, and better handling of user changes in inputs and textareas.

Stuff to keep in mind