Skip to content

Commit ba2791f

Browse files
Merge pull request #108 from ACT-Training/feature/issue-107-livewire4-modernise
Modernise to Livewire 4: replace legacy getXProperty() and $listeners
2 parents 413e92e + b3e9295 commit ba2791f

4 files changed

Lines changed: 23 additions & 40 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,9 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ${{ matrix.os }}
12-
strategy:
13-
fail-fast: true
14-
matrix:
15-
os: [ubuntu-latest, windows-latest]
16-
php: [8.2, 8.1]
17-
laravel: [10.*]
18-
stability: [prefer-lowest, prefer-stable]
19-
include:
20-
- laravel: 10.*
21-
testbench: 8.*
22-
carbon: ^2.63
11+
runs-on: ubuntu-latest
2312

24-
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
13+
name: Tests
2514

2615
steps:
2716
- name: Checkout code
@@ -30,22 +19,12 @@ jobs:
3019
- name: Setup PHP
3120
uses: shivammathur/setup-php@v2
3221
with:
33-
php-version: ${{ matrix.php }}
22+
php-version: 8.2
3423
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
3524
coverage: none
3625

37-
- name: Setup problem matchers
38-
run: |
39-
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
40-
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
41-
4226
- name: Install dependencies
43-
run: |
44-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
45-
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
46-
47-
- name: List Installed Dependencies
48-
run: composer show -D
27+
run: composer install --prefer-dist --no-interaction
4928

5029
- name: Execute tests
5130
run: vendor/bin/pest --ci

src/QueryBuilder.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use Illuminate\Database\Eloquent\Builder;
2929
use Illuminate\Database\Eloquent\Model;
3030
use Illuminate\Support\Str;
31+
use Livewire\Attributes\Computed;
32+
use Livewire\Attributes\On;
3133
use Livewire\Component;
3234

3335
/**
@@ -60,14 +62,11 @@ abstract class QueryBuilder extends Component
6062

6163
public array $rowOptions = [10, 25, 50];
6264

63-
protected $listeners = [
64-
'refreshTable' => '$refresh',
65-
];
66-
67-
// protected array $queryString = ['perPage'];
68-
6965
abstract public function query(): Builder;
7066

67+
#[On('refreshTable')]
68+
public function refreshTable(): void {}
69+
7170
public function booted(): void
7271
{
7372
$this->config();
@@ -98,7 +97,8 @@ public function showQueryBuilder(): bool
9897
return $this->enableQueryBuilder && count($this->conditions());
9998
}
10099

101-
public function getRowsQueryProperty()
100+
#[Computed]
101+
public function rowsQuery()
102102
{
103103
/* @phpstan-ignore-next-line */
104104
$query = $this
@@ -135,7 +135,8 @@ public function getRowsQueryProperty()
135135
return $query;
136136
}
137137

138-
public function getRowsProperty()
138+
#[Computed]
139+
public function rows()
139140
{
140141
// return $this->cache(function () {
141142
return $this->applyPagination($this->rowsQuery); /* @phpstan-ignore-line */

src/TableBuilder.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use Illuminate\Database\Eloquent\Model;
2626
use Illuminate\Support\Arr;
2727
use Illuminate\Support\Str;
28+
use Livewire\Attributes\Computed;
29+
use Livewire\Attributes\On;
2830
use Livewire\Component;
2931
use Psr\Container\ContainerExceptionInterface;
3032
use Psr\Container\NotFoundExceptionInterface;
@@ -50,12 +52,11 @@ abstract class TableBuilder extends Component
5052

5153
public array $rowOptions = [10, 25, 50];
5254

53-
protected $listeners = [
54-
'refreshTable' => '$refresh',
55-
];
56-
5755
abstract public function query(): Builder;
5856

57+
#[On('refreshTable')]
58+
public function refreshTable(): void {}
59+
5960
protected function queryString(): array
6061
{
6162
return [
@@ -78,7 +79,8 @@ public function config(): void
7879
//
7980
}
8081

81-
public function getRowsQueryProperty()
82+
#[Computed]
83+
public function rowsQuery()
8284
{
8385
$query = $this->query()->when($this->sortBy !== '', function ($query) {
8486
if (Str::contains($this->sortBy, '.')) {
@@ -183,7 +185,8 @@ public function getRowsQueryProperty()
183185
* @throws ContainerExceptionInterface
184186
* @throws NotFoundExceptionInterface
185187
*/
186-
public function getRowsProperty()
188+
#[Computed]
189+
public function rows()
187190
{
188191
return $this->applyPagination($this->rowsQuery); /* @phpstan-ignore-line */
189192
}

tests/ArchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
it('will not use debugging functions')
44
->expect(['dd', 'dump', 'ray'])
5-
->each->not->toBeUsed();
5+
->each->not->toBeUsedIn('ACTTraining\QueryBuilder');

0 commit comments

Comments
 (0)