Repository navigation
V3 events API proposal? #5640
Replies: 8 comments 10 replies
|
Currently I don’t have to think about whether my components are siblings or parents/children, and that’s how I prefer it. I need component A to send a message to component B, so I emitTo. So simple. I would not like to have to consider whether it’s a parent / sibling / child. I feel like that’s a step backwards. |
|
So if we go with A: Make the API v2-esque
B: Make API browser-event-esque
A is the most backwards compatible, but it has a more complex implementation and maybe isn't as intuitive. B is more of a seamless path as it leverages basic browser event behavior, but flips the control of scope from dispatchers to listeners, and I want to make sure that doesn't make the feature less useful. Also want to make sure "children-only" isn't a bad default. |
|
I like it! Here goes to me refactoring the game I made using livewire 😂 |
|
I would always vote for long-term significant improvement of the framework at the cost of some reasonable refactoring, so I don't mind the breaking change factor. And as you've described it, in the few cases I use emitUp/To I think the new functionality will still work just fine. Thanks for asking :) |
|
In one special application I use events globally. In that case I have 2 Livewire-Components living together on the same Page. One is kind of a Menu where I can select filters. The second is the Component that shows the results to me. I know this all can be done in different ways, but thats how it grew... If filters are changed in the one component, it is sent to the other via events. So yes - with the window solution this would also work - but currently it's just easy to "emit"... |
|
Hey Caleb, Do your thing. I trust your hunch :) I'm not experienced enough with Livewire, so when you say this
it makes sense, but also... JS (Alpine/Vue/etc) has mechanisms (Store/Pinia/etc or tinyEmmiter/mitt.js) that are handy some time to time! Is this something we wouldn't be able to do in V3's backend with such a change? |
|
I like the idea of unifying the event handling methods in V3, making it more consistent with Alpine. The My opinion is that, as long as we have a way to handle global events and provide a clear migration path, this breaking change is worth it for the long-term benefits. It simplifies event handling and aligns Livewire with Alpine, making it more intuitive for developers. Though it's a breaking change, the long-term benefits are worth it. Clear migration guides would help ease the transition. So I would like |
|
I have always thought that the current event $emitters we have in V2 to be sufficient ,for example one of my concerns is about the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I want to ditch
->emit(),->emitUp(),->emitTo(),->emitSelf, and->dispatchBrowserEvent()......and just got with:
->dispatch()1 simple method on the backend to dispatch a browser event that other Livewire or Alpine components can listen for.
I want it to work just like a normal "click" browser event, meaning the event is dispatched on the root element of the Livewire component and bubbles up from the window.
The "dispatch" part of it feels clear to me, the listener part doesn't.
It makes sense to me to similarly make listeners intuitive: a component event listener is registered on the root element of the component.
But this is a breaking change. A component would only then listen to dispatches from children, not from sibling components like v2.
We could add a simple syntax to allow listeners to be registered on "window" like you would in Alpine to achieve this.
I like that because Livewire and Alpine would basically have the same implementation, mental model, and usage for events and listeners.
But this would be a breaking change and I want to hear from YOU about how you use events and if this change makes sense to you or not.
Thanks!
265 votes ·
All reactions