|
| 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! |
0 commit comments