plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Feature Request]: Livewire Events Click Through

Open ProgrammerZ opened this issue 10 months ago • 2 comments

Feature Description

Would be great to have a click through functionality for Livewire events:

Livewire:

public function livewireFunction() {
    $this->dispatch('event-name');
}

Blade:

 @script
    <script>
        $wire.on('event-name', () => {
            // do something
         })
        // or
        Livewire.on('event-name', () => {
            // do something
         })
    </script>
@endscript

ProgrammerZ avatar Mar 11 '25 20:03 ProgrammerZ

We thought about completing them, but where should Click through go? To the on() call?

adelf avatar Mar 18 '25 11:03 adelf

We thought about completing them, but where should Click through go? To the on() call?

Yes, I believe so.

So when event is dispatched from Livewire component with $this->dispatch('event-name');, I would expect all the following events to match on all Livewire components:

document.addEventListener('event-name', function() {});
$wire.on('event-name', () => {})
Livewire.on('event-name', () => {})

When event is dispatched from JS with Livewire.on('event-name') or $wire.dispatch('event-name') should go to all Livewire components with #[On('event-name')]

If there are multiple it should have the same dropdown as you do next to the Model name.

There are also: dispatchTo() and dispatchSelf()

ProgrammerZ avatar Mar 18 '25 17:03 ProgrammerZ