Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify custom DOM event dispatch #26

Open
allevo opened this issue Aug 11, 2024 · 0 comments
Open

Simplify custom DOM event dispatch #26

allevo opened this issue Aug 11, 2024 · 0 comments
Labels
framework Framework core good first issue Good for newcomers

Comments

@allevo
Copy link
Owner

allevo commented Aug 11, 2024

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.
@allevo allevo added good first issue Good for newcomers framework Framework core labels Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework Framework core good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant