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
toready
. This makes sense now that app() is to become sync #275.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?This doesn’t really appeal to me.
Thanks @ngryman!
I received a lot of great feedback here.
Closing in favor of https://github.com/hyperapp/hyperapp/issues/278.