livewire / volt

Volt is an elegantly crafted functional API for Livewire.
https://livewire.laravel.com/docs/volt
MIT License
312 stars 19 forks source link

Functional API Doesn't Support Interaction to Livewire `$refresh` Magic Action #103

Closed devajmeireles closed 3 months ago

devajmeireles commented 3 months ago

Volt Version

1.6.3

Laravel Version

11.4.0

PHP Version

8.3.6

Database Driver & Version

N/A

Description

While Livewire offers two ways to perform $refresh operation:

In an original Livewire component

Using #[On] on top of the class, implemented here: https://github.com/livewire/livewire/pull/7667

#[On('refresh::create-post')]
class CreatePost extends Component
{
    // ...
}

Using the old approach $listeners:

class CreatePost extends Component
{
    protected $listeners = [
        'refresh::create-post' => '$refresh',
    ];
}

In Volt's functional API style, we have no way of doing this. The docs doesn't mention anything about this. Thinking it would possibly be ready to use, but out of the docs, I tried:

on(['refresh::create-post' => fn () => '$refresh']);

on(['refresh::create-post' => '$refresh']);

None of this worked.

Steps To Reproduce

  1. Create a Volt component using the Functional API
  2. Try to dispatch an event that requires the Livewire $refresh magic action
driesvints commented 3 months ago

Thanks. We'd appreciate a PR to help make this possible.

devajmeireles commented 3 months ago

Thanks. We'd appreciate a PR to help make this possible.

Sure thing! I can try that, but don't you think it's better to keep the issue open with the help wanted label?