mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-07-01 12:22:15 +02:00
🔤 updates texts
This commit is contained in:
34
docs/components/examples/scopes/mixed.js
Normal file
34
docs/components/examples/scopes/mixed.js
Normal file
@ -0,0 +1,34 @@
|
||||
/* PSEUDO-CODE!!! */
|
||||
import { el, scope } from "deka-dom-el";
|
||||
import { S } from "deka-dom-el/signals";
|
||||
function Counter() {
|
||||
const { host } = scope;
|
||||
|
||||
let count = S(0);
|
||||
const counterText = el("p", "Count: 0");
|
||||
S.on(count, c=> counterText.textContent= "Count: " + c);
|
||||
|
||||
// Manually update DOM element
|
||||
const increment = () => {
|
||||
count.set(count.get() + 1);
|
||||
// NEVER EVER
|
||||
// count = S(count.get() + 1);
|
||||
host().querySelector("button").disabled = count.get() >= 10;
|
||||
};
|
||||
// NEVER EVER
|
||||
// setTimeout(()=> {
|
||||
// const wrong= S(0);
|
||||
// // THE HOST IS PROBABLY DIFFERENT THAN
|
||||
// // YOU EXPECT AND OBSERVABLES MAY BE
|
||||
// // UNEXPECTEDLY REMOVED!!!
|
||||
// counterText.textContent= "Count: " + wrong.get();
|
||||
// }, 1000);
|
||||
|
||||
return el("div").append(
|
||||
counterText,
|
||||
el("button", {
|
||||
onclick: increment,
|
||||
textContent: "Increment"
|
||||
})
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user