Skip to content

Commit

Permalink
Removing old $listeners approach (#1821)
Browse files Browse the repository at this point in the history
* Removing old $listeners approach

* Add comments that the events are no longer used


---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Aug 4, 2024
1 parent 664e119 commit 8b3b223
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@

namespace Rappasoft\LaravelLivewireTables;

use Livewire\Attributes\On;
use Livewire\Component;
use Rappasoft\LaravelLivewireTables\Traits\HasAllTraits;

abstract class DataTableComponent extends Component
{
use HasAllTraits;

/** @phpstan-ignore-next-line */
protected $listeners = [
'refreshDatatable' => '$refresh',
'setSort' => 'setSortEvent',
'clearSorts' => 'clearSortEvent',
'setFilter' => 'setFilterEvent',
'clearFilters' => 'clearFilterEvent',
];

/**
* Runs on every request, immediately after the component is instantiated, but before any other lifecycle methods are called
*/
#[On('refreshDatatable')]
public function boot(): void
{
//
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/Helpers/FilterHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function getFilterByKey(string $key)
});
}

#[On('setFilter')]
#[On('set-filter')]
public function setFilter(string $filterKey, mixed $value): void
{
Expand Down Expand Up @@ -163,6 +164,7 @@ public function selectAllFilterOptions(string $filterKey): void
$this->setFilter($filterKey, array_keys($filter->getOptions()));
}

#[On('clearFilters')]
#[On('clear-filters')]
public function setFilterDefaults(): void
{
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/Helpers/SortingHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getSort(string $field): ?string
return $this->sorts[$field] ?? null;
}

#[On('setSort')]
#[On('set-sort')]
public function setSort(string $field, string $direction): string
{
Expand All @@ -58,6 +59,7 @@ public function hasSort(string $field): bool
/**
* Clear the sorts array
*/
#[On('clearSorts')]
#[On('clearsorts')]
public function clearSorts(): void
{
Expand Down
4 changes: 4 additions & 0 deletions src/Traits/WithEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ trait WithEvents

protected array $eventStatuses = ['columnSelected' => true, 'searchApplied' => false, 'filterApplied' => false];

// No Longer Used
public function setSortEvent(string $field, string $direction): void
{
$this->setSort($field, $direction);
}

// No Longer Used
public function clearSortEvent(): void
{
$this->clearSorts();
}

// No Longer Used
public function setFilterEvent(string $filter, string $value): void
{
$this->setFilter($filter, $value);
}

// No Longer Used
public function clearFilterEvent(): void
{
$this->setFilterDefaults();
Expand Down

0 comments on commit 8b3b223

Please sign in to comment.