question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Revamp events/emit API.

See original GitHub issue

#259 has been merged, #275 is also on the way and we’ve decoupled the event emitter from app().

Thanks @zaceno and everyone else: @lukejacksonn @selfup @jamen @dodekeract who contributed to the discussion.

As a result, you can now create isolated hyperapps that can communicate to each other or use the emitter to communicate with your hyperapp from other parts of your application.

I think the API now looks wonkier, however, but I just had an idea about how we could utilize #259 to revamp the events API and events function signature.

Code is worth a thousand comments so here is what I am talking about:

const { emit } = app({ state, view, actions, mixins })
  .on("ready", (state, actions, data /*,emit*/) => {
    /*
      We don't need emit as a last argument here anymore.
    */
  })
  .on("render", (state, actions, data) => {})
  .on("action", (state, actions, data) => {})
  .on("update", (state, actions, data) => {})

As for mixins, we can simply pass the emitter to them.

const MyMixin = (app, { emit, on }) => ({
  ...
})

Changes

  • This means we don’t need app.events anymore.
  • I’ve also renamed loaded to ready. This makes sense now that app() is to become sync #275.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
jamencommented, Jul 4, 2017

I’m not really a fan of adding .on(...). It seems like an odd addition to me, when everything else is specified through the object. I like how centered that is personally.

Also, inside mixins are you supposed to set emit.on(...) at the base?

const MyMixin = (app, emit) => {
  emit.on('ready', (state, actions) => {
    // ...
  })

  return {
    actions,
    state,
    // ...
  }
}

This doesn’t really appeal to me.

2reactions
jorgebucarancommented, Jul 4, 2017

Thanks @ngryman!

I received a lot of great feedback here.

Closing in favor of https://github.com/hyperapp/hyperapp/issues/278.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[V2] runtime.EventsEmit not working with custom struct #1037
When I change it to runtime.EventsEmit(app.ctx, "importEvent", eventData.objekte) it works again. The code on the Vue side is very minimal:.
Read more >
Events - Atlassian Developer
Adds a listener for all occurrences of an event of a particular name. Listener arguments include any arguments passed to events.emit , followed...
Read more >
Events — Obsidian Framework documentation - GitHub Pages
To emit an event, use events.emit() as follows: app.events.emit("my-event.path", ... app.events.emit("ready"); app.events.emit("my-model.value-change"); ...
Read more >
Vortex API Events - Nexus Mods Wiki
Interacting with events. You can both catch and emit all events inside Vortex. The Vortex API is accessed as a property of the...
Read more >
Creating and triggering events - MDN Web Docs - Mozilla
This article demonstrates how to create and dispatch DOM events. Such events are commonly called synthetic events, as opposed to the events ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found