mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-25 01:39:37 +01:00
♻️ use eventsSink for n-binding
This commit is contained in:
parent
31563c4f7b
commit
7a2c3e6a4b
12
README.md
12
README.md
@ -98,16 +98,14 @@ document.body.append(
|
||||
```
|
||||
|
||||
## Events and dynamic parts
|
||||
*investigation*:
|
||||
```js
|
||||
const output_dynamic= (function(){
|
||||
const element= el("span", { style: { fontWeight: "bold" }, textContent: "" });
|
||||
return {
|
||||
const output_dynamic= eventsSink(store=> ({
|
||||
element,
|
||||
onchange: listen("change", event=> assign(element, { textContent: event.target.value }))
|
||||
};
|
||||
})();
|
||||
onchange: listen("change", event=> assign(store.element, { textContent: event.target.value }))
|
||||
}));
|
||||
document.body.append(
|
||||
output_dynamic.element,
|
||||
el("span", { style: { fontWeight: "bold" }, textContent: "" }, output_dynamic.target),
|
||||
el("input", { type: "text" }, output_dynamic.onchange)
|
||||
);
|
||||
```
|
||||
|
@ -22,36 +22,36 @@ function component({ value= "World" }= {}){
|
||||
}
|
||||
`;
|
||||
|
||||
const output= (function(){
|
||||
const element= el("strong", { textContent: value });
|
||||
return {
|
||||
element,
|
||||
const output= eventsSink(store=> ({
|
||||
onchange: listen("change", function(event){
|
||||
assign(element, { textContent: event.target.value });
|
||||
assign(store.element, { textContent: event.target.value });
|
||||
})
|
||||
}
|
||||
})();
|
||||
const input= (function(){
|
||||
const element= el("input", { type: "text", value }, output.onchange);
|
||||
return {
|
||||
element,
|
||||
}));
|
||||
const input= eventsSink(store=> ({
|
||||
onchange: listen("change", function(event){
|
||||
assign(element, { value: event.detail });
|
||||
dispatch("change")(element);
|
||||
assign(store.element, { value: event.detail });
|
||||
dispatch("change")(input.element);
|
||||
})
|
||||
};
|
||||
})();
|
||||
}));
|
||||
return el("div", { className: name }, input.onchange).append(
|
||||
el("p").append(
|
||||
el("#text", { textContent: "Hello " }),
|
||||
output.element,
|
||||
el("strong", { textContent: value }, output.target),
|
||||
),
|
||||
el("label").append(
|
||||
el("#text", { textContent: "Set name:" }),
|
||||
input.element
|
||||
el("input", { type: "text", value }, output.onchange, input.target)
|
||||
)
|
||||
)
|
||||
}
|
||||
function eventsSink(fn){
|
||||
const store= {
|
||||
element: null,
|
||||
target: function(element){ store.element= element; },
|
||||
};
|
||||
Object.assign(store, fn(store));
|
||||
return store;
|
||||
}
|
||||
function createStyle(){
|
||||
const style= el("style");
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user