8000 Adding CHANGELOG for twig/live component · symfony/ux@ddac904 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddac904

Browse files
committed
Adding CHANGELOG for twig/live component
1 parent 4e7cd8c commit ddac904

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

src/LiveComponent/CHANGELOG.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# CHANGELOG
2+
3+
## NEXT
4+
5+
- Minimum PHP version was bumped to 8.0 so that PHP 8 attributes could be used.
6+
7+
- The `LiveComponentInterface` was dropped and replaced by the `AsLiveComponent` attribute,
8+
which extends the new `AsTwigComponent` from the TwigComponent library. All
9+
other annotations (e.g. `@LiveProp` and `@LiveAction`) were also replaced by
10+
PHP 8 attributes.
11+
12+
Before:
13+
14+
```php
15+
use App\Entity\Notification;
16+
use App\Repository\NotificationRepository;
17+
use Symfony\UX\LiveComponent\Attribute\LiveAction;
18+
use Symfony\UX\LiveComponent\Attribute\LiveProp;
19+
use Symfony\UX\LiveComponent\LiveComponentInterface;
20+
21+
final class NotificationComponent implements LiveComponentInterface
22+
{
23+
private NotificationRepository $repo;
24+
25+
/** @LiveProp */
26+
public bool $expanded = false;
27+
28+
public function __construct(NotificationRepository $repo)
29+
{
30+
$this->repo = $repo;
31+
}
32+
33+
/** @LiveAction */
34+
public function toggle(): void
35+
{
36+
$this->expanded = !$this->expanded;
37+
}
38+
39+
public function getNotifications(): array
40+
{
41+
return $this->repo->findAll();
42+
}
43+
44+
public static function getComponentName(): string
45+
{
46+
return 'notification';
47+
}
48+
}
49+
```
50+
51+
After:
52+
53+
```php
54+
use App\Entity\Notification;
55+
use App\Repository\NotificationRepository;
56+
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
57+
use Symfony\UX\LiveComponent\Attribute\LiveAction;
58+
use Symfony\UX\LiveComponent\Attribute\LiveProp;
59+
60+
#[AsLiveComponent('notification')]
61+
final class NotificationComponent
62+
{
63+
private NotificationRepository $repo;
64+
65+
#[LiveProp]
66+
public bool $expanded = false;
67+
68+
public function __construct(NotificationRepository $repo)
69+
{
70+
$this->repo = $repo;
71+
}
72+
73+
#[LiveAction]
74+
public function toggle(): void
75+
{
76+
$this->expanded = !$this->expanded;
77+
}
78+
79+
public function getNotifications(): array
80+
{
81+
return $this->repo->findAll();
82+
}
83+
}
84+
```
85+
86+
## Pre-Release
87+
88+
- The LiveComponent library was introduced!

src/TwigComponent/CHANGELOG.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# CHANGELOG
2+
3+
## NEXT
4+
5+
- Minimum PHP version was bumped to 8.0 so that PHP 8 attributes could be used.
6+
7+
- The `ComponentInterface` was dropped and replaced by the `AsTwigComponent` attribute.
8+
The `getComponentName()` was replaced by a `name` argument to the attribute.
9+
10+
Before:
11+
12+
```php
13+
use Symfony\UX\TwigComponent\ComponentInterface;
14+
15+
class AlertComponent implements ComponentInterface
16+
{
17+
public string $type = 'success';
18+
public string $message;
19+
20+
public static function getComponentName(): string
21+
{
22+
return 'alert';
23+
}
24+
}
25+
```
26+
27+
After:
28+
29+
```php
30+
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
31+
32+
#[AsTwigComponent('alert')]
33+
class AlertComponent
34+
{
35+
public string $type = 'success';
36+
public string $message;
37+
}
38+
```
39+
40+
- If you're using a version _lower_ than Symfony 5.3, you will need
41+
to manually tag all component services with `twig.component`. This is
42+
because Symfony 5.3 introduces autoconfiguration for PHP 8 attributes,
43+
which this library leverages.
44+
45+
- The template for a component can now be controlled via the `template` argument
46+
to the `AsTwigComponent` attribute:
47+
48+
```php
49+
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
50+
51+
#[AsTwigComponent('alert', template: 'other/path/alert.html.twig')]
52+
class AlertComponent
53+
{
54+
// ...
55+
}
56+
```
57+
58+
## Pre-Release
59+
60+
- The TwigComponent library was introduced!

0 commit comments

Comments
 (0)
0