Skip to content

Suggestion: .$listeners and .$style #15

Open
@K4rakara

Description

@K4rakara

It would be pretty great to be able to create event listeners in WebScript. Heres an example of what I mean:

const { div } = builders(createDOMElement);

document.body.appendChild(
   div.class`my-actions`(
      div.class`button first-button`.$listeners({
         'mousedown': (el, ev) => {
            console.log('The first button was pressed!');
         }
      }),
      div.class`button second-button`.$listeners({
         'mousedown': [
            (el, ev) => {
               console.log('The second button was pressed!')
            },
            (el, ev) => {
               console.log('I am also called when the second button is pressed!');
            }
         ]
      })));

In terms of implementation, I believe you would need to have something interject in setPropertyValue if the elementName is "$listener", and then store it somewhere until the actual element is constructed.

People may also find it useful to be able to set the styles with $style, but idk.

Hopefully this wouldn't be too painful to implement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions