Skip to content

Simplify custom DOM event dispatch #26

@allevo

Description

@allevo

Improve child->parent communication.
For the time being, child components can send events to parents in 2 ways:

  • domain event (alway using a external domain class -> heavy)
  • dom event (cannot be customizable -> bad)
    Meanwhile, the first is well-typed and structured, but the second isn't.
    We would like Seqflow helps the developer to build CustomEvent so the parent can listen it.

We can write something like

const MyNewDomEvent = createDomEventClass<{ foo: string }>('my-dom-event')

async function ChildComponent({}, { component }: Contexts) {
  // something happen
  component.dispatchEvent(new MyNewDomEvent({ foo: 'a string' }))
}
async function ParentComponent({}, { component }: Contexts) {
  // render ChildComponent

  const events = component.waitEvents(component.domEvent(MyNewDomEvent))
  for await (const ev of events) {
    console.log(ev) // ev instanceof MyNewDomEvent
  }
}

With this issue the assignee should:

  • create and export a function createDomEventClass to help the developer create custom dom event
  • improve the domEvent method to allow custom dom event
    The createDomainEventClass function can help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions