Skip to content

Commit

Permalink
Merge pull request #34498 from stancl/varied-dynamic-calls
Browse files Browse the repository at this point in the history
Allow for dynamic calls of anonymous component with varied attributes
  • Loading branch information
taylorotwell authored Sep 23, 2020
2 parents 689b172 + 9b8f94e commit aabd2c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/Illuminate/View/DynamicComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ class DynamicComponent extends Component
*/
protected static $componentClasses = [];

/**
* The cached binding keys for component classes.
*
* @var array
*/
protected static $bindings = [];

/**
* Create a new component instance.
*
Expand Down Expand Up @@ -153,13 +146,9 @@ protected function classForComponent()
*/
protected function bindings(string $class)
{
if (! isset(static::$bindings[$class])) {
[$data, $attributes] = $this->compiler()->partitionDataAndAttributes($class, $this->attributes->getAttributes());

static::$bindings[$class] = array_keys($data->all());
}
[$data, $attributes] = $this->compiler()->partitionDataAndAttributes($class, $this->attributes->getAttributes());

return static::$bindings[$class];
return array_keys($data->all());
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/View/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ public function test_rendering_a_dynamic_component()
</div>', trim($view));
}

public function test_rendering_the_same_dynamic_component_with_different_attributes()
{
$view = View::make('varied-dynamic-calls')->render();

$this->assertEquals('<span class="text-medium">
Hello Taylor
</span>
<span >
Hello Samuel
</span>', trim($view));
}

protected function getEnvironmentSetUp($app)
{
$app['config']->set('view.paths', [__DIR__.'/templates']);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@props([
'name',
])

<span {{ $attributes }}>
Hello {{ $name }}
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<x-dynamic-component component="hello-span" name="Taylor" class="text-medium" />
<x-dynamic-component component="hello-span" name="Samuel" />

0 comments on commit aabd2c9

Please sign in to comment.