Skip to content

Commit bd05418

Browse files
committed
Renames and comments
1 parent f7dbdc1 commit bd05418

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

src/LiveComponent/assets/src/update_array_data.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@
77
* return the final, updated array (e.g. ["text", "phone", "email"]).
88
*
99
* @param element Current HTML element
10-
* @param value Resolved value of a single HTML element (.value or [data-value])
11-
* @param currentValue Current data value
10+
* @param value The value that should be set or removed from currentValues
11+
* @param currentValues Current data value
1212
*/
1313
export function updateArrayDataFromChangedElement(
1414
element: HTMLElement,
1515
value: string|null,
16-
currentValue: any
16+
currentValues: any
1717
): Array<string> {
1818
// Enforce returned value is an array
19-
if (!(currentValue instanceof Array)) {
20-
currentValue = [];
19+
if (!(currentValues instanceof Array)) {
20+
currentValues = [];
2121
}
2222

2323
if (element instanceof HTMLInputElement && element.type === 'checkbox') {
24-
const index = currentValue.indexOf(value);
24+
const index = currentValues.indexOf(value);
2525

2626
if (element.checked) {
2727
// Add value to an array if it's not in it already
2828
if (index === -1) {
29-
currentValue.push(value);
29+
currentValues.push(value);
3030
}
3131
} else {
3232
// Remove value from an array
3333
if (index > -1) {
34-
currentValue.splice(index, 1);
34+
currentValues.splice(index, 1);
3535
}
3636
}
3737
} else if (element instanceof HTMLSelectElement) {
3838
// Select elements with `multiple` option require mapping chosen options to their values
39-
currentValue = Array.from(element.selectedOptions).map(el => el.value);
39+
currentValues = Array.from(element.selectedOptions).map(el => el.value);
4040
}
4141

4242
// When no values are selected for collection no data should be sent over the wire
43-
return currentValue;
43+
return currentValues;
4444
}

src/LiveComponent/tests/Fixtures/Component/FormComponent1.php renamed to src/LiveComponent/tests/Fixtures/Component/FormComponentWithManyDifferentFieldsType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
1818
use Symfony\UX\LiveComponent\ComponentWithFormTrait;
1919
use Symfony\UX\LiveComponent\DefaultActionTrait;
20-
use Symfony\UX\LiveComponent\Tests\Fixtures\Form\FormType1;
20+
use Symfony\UX\LiveComponent\Tests\Fixtures\Form\FormWithManyDifferentFieldsType;
2121

2222
/**
2323
* @author Jakub Caban <[email protected]>
2424
*/
25-
#[AsLiveComponent('form_component1')]
26-
class FormComponent1 extends AbstractController
25+
#[AsLiveComponent('form_with_many_different_fields_type')]
26+
class FormComponentWithManyDifferentFieldsType extends AbstractController
2727
{
2828
use ComponentWithFormTrait;
2929
use DefaultActionTrait;
@@ -34,6 +34,6 @@ public function __construct(private FormFactoryInterface $formFactory)
3434

3535
protected function instantiateForm(): FormInterface
3636
{
37-
return $this->formFactory->createNamed('form', FormType1::class);
37+
return $this->formFactory->createNamed('form', FormWithManyDifferentFieldsType::class);
3838
}
3939
}

src/LiveComponent/tests/Fixtures/Form/FormType1.php renamed to src/LiveComponent/tests/Fixtures/Form/FormWithManyDifferentFieldsType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* @author Jakub Caban <[email protected]>
2929
*/
30-
class FormType1 extends AbstractType
30+
class FormWithManyDifferentFieldsType extends AbstractType
3131
{
3232
public function buildForm(FormBuilderInterface $builder, array $options)
3333
{

src/LiveComponent/tests/Fixtures/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\Component2;
2727
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\Component3;
2828
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\Component6;
29-
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponent1;
29+
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponentWithManyDifferentFieldsType;
3030
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\ComponentWithAttributes;
3131
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormWithCollectionTypeComponent;
3232
use Symfony\UX\TwigComponent\TwigComponentBundle;
@@ -70,7 +70,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
7070
$c->register(Component3::class)->setAutoconfigured(true)->setAutowired(true);
7171
$c->register(Component6::class)->setAutoconfigured(true)->setAutowired(true);
7272
$c->register(ComponentWithAttributes::class)->setAutoconfigured(true)->setAutowired(true);
73-
$c->register(FormComponent1::class)->setAutoconfigured(true)->setAutowired(true);
73+
$c->register(FormComponentWithManyDifferentFieldsType::class)->setAutoconfigured(true)->setAutowired(true);
7474
$c->register(FormWithCollectionTypeComponent::class)->setAutoconfigured(true)->setAutowired(true);
7575

7676
$c->loadFromExtension('framework', [

src/LiveComponent/tests/Functional/Form/ComponentWithFormTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\DomCrawler\Crawler;
1818
use Symfony\Component\Form\FormFactoryInterface;
1919
use Symfony\UX\LiveComponent\LiveComponentHydrator;
20-
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponent1;
20+
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponentWithManyDifferentFieldsType;
2121
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormWithCollectionTypeComponent;
2222
use Symfony\UX\LiveComponent\Tests\Fixtures\Form\BlogPostFormType;
2323
use Symfony\UX\TwigComponent\ComponentFactory;
@@ -156,8 +156,8 @@ public function testHandleCheckboxChanges(): void
156156
/** @var ComponentFactory $factory */
157157
$factory = self::getContainer()->get('ux.twig_component.component_factory');
158158

159-
/** @var FormComponent1 $component */
160-
$component = $factory->create('form_component1');
159+
/** @var FormComponentWithManyDifferentFieldsType $component */
160+
$component = $factory->create('form_with_many_different_fields_type');
161161

162162
$dehydrated = $hydrator->dehydrate($component);
163163
$bareForm = [
@@ -181,7 +181,7 @@ public function testHandleCheckboxChanges(): void
181181

182182
$this->browser()
183183
->throwExceptions()
184-
->get('/_components/form_component1?data='.urlencode(json_encode($dehydrated)))
184+
->get('/_components/form_with_many_different_fields_type?data='.urlencode(json_encode($dehydrated)))
185185
->assertSuccessful()
186186
->assertContains('<input type="checkbox" id="form_choice_multiple_1" name="form[choice_multiple][]" value="2" checked="checked" />')
187187
->assertContains('<input type="checkbox" id="form_choice_multiple_0" name="form[choice_multiple][]" value="1" />')
@@ -199,7 +199,7 @@ public function testHandleCheckboxChanges(): void
199199

200200
$dehydrated['form'] = $bareForm;
201201
})
202-
->get('/_components/form_component1?data='.urlencode(json_encode($dehydrated)))
202+
->get('/_components/form_with_many_different_fields_type?data='.urlencode(json_encode($dehydrated)))
203203
->assertContains('<input type="checkbox" id="form_choice_multiple_1" name="form[choice_multiple][]" value="2" checked="checked" />')
204204
->assertContains('<input type="checkbox" id="form_choice_multiple_0" name="form[choice_multiple][]" value="1" checked="checked" />')
205205
->use(function (HtmlResponse $response) use (&$fullBareData, &$dehydrated, &$bareForm) {
@@ -219,7 +219,7 @@ public function testHandleCheckboxChanges(): void
219219

220220
$dehydrated['form'] = $bareForm;
221221
})
222-
->get('/_components/form_component1?data='.urlencode(json_encode($dehydrated)))
222+
->get('/_components/form_with_many_different_fields_type?data='.urlencode(json_encode($dehydrated)))
223223
->assertContains('<input type="checkbox" id="form_choice_multiple_1" name="form[choice_multiple][]" value="2" />')
224224
->assertContains('<input type="checkbox" id="form_choice_multiple_0" name="form[choice_multiple][]" value="1" />')
225225
->assertContains('<input type="checkbox" id="form_checkbox" name="form[checkbox]" required="required" value="1" checked="checked" />')
@@ -236,7 +236,7 @@ public function testHandleCheckboxChanges(): void
236236

237237
$dehydrated['form'] = $bareForm;
238238
})
239-
->get('/_components/form_component1?data='.urlencode(json_encode($dehydrated)))
239+
->get('/_components/form_with_many_different_fields_type?data='.urlencode(json_encode($dehydrated)))
240240
->assertContains('<option value="2" selected="selected">')
241241
->assertContains('<option value="1" selected="selected">')
242242
->use(function (HtmlResponse $response) use ($fullBareData) {

src/LiveComponent/tests/Unit/Form/ComponentWithFormTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace Symfony\UX\LiveComponent\Tests\Unit\Form;
1515

1616
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
17-
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponent1;
17+
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponentWithManyDifferentFieldsType;
1818

1919
/**
2020
* @author Jakub Caban <[email protected]>
@@ -24,7 +24,7 @@ class ComponentWithFormTest extends KernelTestCase
2424
public function testFormValues(): void
2525
{
2626
$formFactory = self::getContainer()->get('form.factory');
27-
$component = new FormComponent1($formFactory);
27+
$component = new FormComponentWithManyDifferentFieldsType($formFactory);
2828
$component->postMount([]);
2929

3030
$this->assertSame(

0 commit comments

Comments
 (0)