This repository was archived by the owner on Jan 9, 2026. It is now read-only.
forked from jaandrle/dollar_dom_component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_t1.sub.html
More file actions
32 lines (26 loc) · 1.76 KB
/
example_t1.sub.html
File metadata and controls
32 lines (26 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
gulp_place("app._BUILD_.example_el= toELID(app._BUILD_.example_el_id++)", "eval");
gulp_place("app._BUILD_.example_onkeyup= toKeyUp(app._BUILD_.example_el)", "eval");
<p>You can define listener outside function scope (see <a href="https://github.com/jaandrle/dollar_dom_component/blob/master/docs/%24dom_component.md#module_jaaJSU..$dom.componentListener"><code>$dom.componentListener</code></a>):</p>
<div class="output" id="gulp_place('app._BUILD_.example_el', 'variable')"></div>
<script onkeyup="gulp_place('app._BUILD_.example_onkeyup', 'variable')" contenteditable="">
(function(element_id){
//EXAMPLE START
const container= document.getElementById(element_id);
const update_ChangeSum= $dom.componentListener("update", { sum: 0 }, ({ sum })=> ({ textContent: sum }));
const update_ChangeColor= $dom.componentListener("update", { color: "blue" }, ({ color })=> ({ className: `example_${color}_color` }));
counterComponent({ textContent: "Number of yours socks: " }).mount(container);
function counterComponent({ textContent }){
const click_addOne= $dom.componentListener("click", function(){ this.update(({ sum })=> ({ sum: sum+1 })) });
const { add, share, update }= $dom.component("DIV", null);
add("BUTTON", { textContent: "+" }).on(click_addOne);
add("BUTTON", { textContent: "red", onclick: setColor }, -1);
add("BUTTON", { textContent: "blue", onclick: setColor }, -1);
add("P", { textContent }, -1);
add("STRONG", null).on(update_ChangeSum, update_ChangeColor);
return share;
function setColor(){ update({ color: this.textContent }); }
}
//EXAMPLE END
})("gulp_place('app._BUILD_.example_el', 'variable')");
</script>
<!-- example source links -->