Skip to content

Commit 11b1ebc

Browse files
committed
Update doc, changelog, fix tests using fieldname and url binding
1 parent 3ef4ace commit 11b1ebc

File tree

8 files changed

+32
-13
lines changed

8 files changed

+32
-13
lines changed

src/LiveComponent/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# CHANGELOG
22

3+
## 2.17.0
4+
5+
- Add `modifier` option in `LiveProp` so options can be modified at runtime.
6+
37
## 2.15.0
48

59
- [BC BREAK] The `data-live-id` attribute was changed to `id` #1484
610
- Fixed child handling bug during re-rendering introduced with the
711
new morphing library in 2.14.0 #1484
812
- Fix bug where the active input would maintain its value, but lose its cursor position #1501
913
- Restrict Twig 3.9 for now #1486
10-
- Add `modifier` option in `LiveProp` so options can be modified at runtime.
1114

1215
## 2.14.1
1316

src/LiveComponent/doc/index.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,9 +3351,9 @@ the change of one specific key::
33513351
Set LiveProp Options Dynamically
33523352
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33533353

3354-
.. versionadded:: 2.15
3354+
.. versionadded:: 2.17
33553355

3356-
The ``modifier`` option was added in LiveComponents 2.15.
3356+
The ``modifier`` option was added in LiveComponents 2.17.
33573357

33583358

33593359
If you need to configure a LiveProp's options dynamically, you can use the ``modifier`` option to use a custom
@@ -3364,7 +3364,7 @@ method in your component that returns a modified version of your LiveProp::
33643364
class ProductSearch
33653365
{
33663366
#[LiveProp(writable: true, modifier: 'modifyAddedDate')]
3367-
public ?\DateTimeImmutable $addedDate;
3367+
public ?\DateTimeImmutable $addedDate = null;
33683368

33693369
#[LiveProp]
33703370
public string $dateFormat = 'Y-m-d';
@@ -3390,8 +3390,9 @@ All ``LiveProp::with*`` methods are immutable, so you need to use their return v
33903390

33913391
.. caution::
33923392

3393-
You must not rely on props that also use a modifier in other modifiers methods. This is because
3394-
those properties may not have been hydrated by this point.
3393+
Avoid relying on props that also use a modifier in other modifiers methods. For example, if the ``$dateFormat``
3394+
property above also had a ``modifier`` option, then it wouldn't be safe to reference it from the ``modifyAddedDate``
3395+
modifier method. This is because the ``$dateFormat`` property may not have been hydrated by this point.
33953396

33963397

33973398
Debugging Components

src/LiveComponent/tests/Fixtures/Component/ComponentWithUrlBoundProps.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@ class ComponentWithUrlBoundProps
3939
#[LiveProp(fieldName: 'field6', url: true)]
4040
public ?string $prop6 = null;
4141

42-
#[LiveProp(modifier: 'modifyProp7')]
42+
#[LiveProp(fieldName: 'getProp7Name()', url: true)]
4343
public ?string $prop7 = null;
4444

45+
#[LiveProp(modifier: 'modifyProp8')]
46+
public ?string $prop8 = null;
47+
4548
#[LiveProp]
46-
public ?bool $prop7InUrl = false;
49+
public ?bool $prop8InUrl = false;
50+
51+
public function getProp7Name(): string
52+
{
53+
return 'field7';
54+
}
4755

48-
public function modifyProp7(LiveProp $prop): LiveProp
56+
public function modifyProp8(LiveProp $prop): LiveProp
4957
{
50-
return $prop->withUrl($this->prop7InUrl);
58+
return $prop->withUrl($this->prop8InUrl);
5159
}
5260
}

src/LiveComponent/tests/Fixtures/templates/components/component_with_url_bound_props.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
Prop5: address: {{ prop5.address ?? '' }} city: {{ prop5.city ?? '' }}
77
Prop6: {{ prop6 }}
88
Prop7: {{ prop7 }}
9+
Prop8: {{ prop8 }}
910
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{{ component('component_with_url_bound_props', {
2-
prop7InUrl: true
2+
prop8InUrl: true
33
}) }}

src/LiveComponent/tests/Functional/EventListener/AddLiveAttributesSubscriberTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ public function testQueryStringMappingAttribute()
151151
'prop3' => ['name' => 'prop3'],
152152
'prop5' => ['name' => 'prop5'],
153153
'field6' => ['name' => 'field6'],
154-
'prop7' => ['name' => 'prop7'],
154+
'field7' => ['name' => 'field7'],
155+
'prop8' => ['name' => 'prop8'],
155156
];
156157

157158
$this->assertEquals($expected, $queryMapping);

src/LiveComponent/tests/Functional/EventListener/QueryStringInitializerSubscriberTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testQueryStringPropsInitialization()
2222
{
2323
$this->browser()
2424
->throwExceptions()
25-
->get('/render-template/render_component_with_url_bound_props?prop1=foo&prop2=42&prop3[]=foo&prop3[]=bar&prop4=unbound&prop5[address]=foo&prop5[city]=bar&field6=foo&prop7=foo')
25+
->get('/render-template/render_component_with_url_bound_props?prop1=foo&prop2=42&prop3[]=foo&prop3[]=bar&prop4=unbound&prop5[address]=foo&prop5[city]=bar&field6=foo&field7=foo&prop8=foo')
2626
->assertSuccessful()
2727
->assertContains('Prop1: foo')
2828
->assertContains('Prop2: 42')
@@ -31,6 +31,7 @@ public function testQueryStringPropsInitialization()
3131
->assertContains('Prop5: address: foo city: bar')
3232
->assertContains('Prop6: foo')
3333
->assertContains('Prop7: foo')
34+
->assertContains('Prop8: foo')
3435
;
3536
}
3637
}

src/LiveComponent/tests/Functional/Metadata/LiveComponentMetadataFactoryTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@ public function testQueryStringMapping()
4141
$this->assertTrue($propsMetadataByName['prop5']->queryStringMapping());
4242

4343
$this->assertTrue($propsMetadataByName['prop6']->queryStringMapping());
44+
45+
$this->assertTrue($propsMetadataByName['prop7']->queryStringMapping());
46+
47+
$this->assertFalse($propsMetadataByName['prop8']->queryStringMapping());
4448
}
4549
}

0 commit comments

Comments
 (0)