Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Events exposion via .share? #4

Description

@jaandrle

https://developer.mozilla.org/en-US/docs/Web/API/EventListener

Current

testA({ onclick: console.log }).mount(somewhere);
function testA({ onclick: onclickPublic }){
    const onclick= function(ev){ onclickPublic.call(this, ev); console.log("Multiple+internal"); };
    return $dom.component("P", { textContent: "test", onclick }).share;
}
testB({ onclick: console.log }).mount(somewhere);
function testB({ onclick }){
    return $dom.component("P", { textContent: "test" })
    .oninit(el=> el.addEventListener("click", onclick))
    .oninit(el=> el.addEventListener("click", console.log.bind(null, "Multiple+internal")))
    .share;
}
testC({ onclick: console.log }).mount(somewhere);
function testC({ onclick }){
    const c= $dom.component("P", { textContent: "test" });
    const el= c.getReference();
    el.addEventListener("click", onclick);
    el.addEventListener("click", console.log.bind(null, "Multiple+internal"));
    return c.share;
}

New?

const log_click= $dom.componentListener("click", console.log);


testD({ listeners: [ log_click ] }).mount(somewhere);
function testD({ listeners }){
    return $dom.component("P", { textContent: "test" })
    .on(...listeners)//?
    .share;
}


const c= testE({ listeners: [ log_click ] });
c.addEventListener("public_name", console.log);
c.addEventListener("public_name", function(ev){ //???
    this.update(({ counter })=> ({ counter: counter+1 }));
});
c.mount(somewhere);

function testE(){
    return $dom.component("P")
    .onevent("click", "public_name" /*, ...args */)//?
    .onupdate({ counter: 1 }, ({ counter })=> ({ textContent: `Test ${counter}.` })) //???
    .share;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions