From 9b8f94e7561cd2548522983c37411b3f04f73c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 23 Sep 2020 18:40:53 +0200 Subject: [PATCH] Allow for dynamic calls of anonymous component with varied attributes, add regression test --- src/Illuminate/View/DynamicComponent.php | 15 ++------------- tests/Integration/View/BladeTest.php | 13 +++++++++++++ .../templates/components/hello-span.blade.php | 7 +++++++ .../View/templates/varied-dynamic-calls.blade.php | 2 ++ 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 tests/Integration/View/templates/components/hello-span.blade.php create mode 100644 tests/Integration/View/templates/varied-dynamic-calls.blade.php diff --git a/src/Illuminate/View/DynamicComponent.php b/src/Illuminate/View/DynamicComponent.php index 793c34e05241..7133f4f29af7 100644 --- a/src/Illuminate/View/DynamicComponent.php +++ b/src/Illuminate/View/DynamicComponent.php @@ -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. * @@ -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()); } /** diff --git a/tests/Integration/View/BladeTest.php b/tests/Integration/View/BladeTest.php index 5f4b3d10ab0b..36f47e8e5056 100644 --- a/tests/Integration/View/BladeTest.php +++ b/tests/Integration/View/BladeTest.php @@ -35,6 +35,19 @@ public function test_rendering_a_dynamic_component() ', trim($view)); } + public function test_rendering_the_same_dynamic_component_with_different_attributes() + { + $view = View::make('varied-dynamic-calls')->render(); + + $this->assertEquals(' + Hello Taylor + + + + Hello Samuel +', trim($view)); + } + protected function getEnvironmentSetUp($app) { $app['config']->set('view.paths', [__DIR__.'/templates']); diff --git a/tests/Integration/View/templates/components/hello-span.blade.php b/tests/Integration/View/templates/components/hello-span.blade.php new file mode 100644 index 000000000000..fac695a4acbf --- /dev/null +++ b/tests/Integration/View/templates/components/hello-span.blade.php @@ -0,0 +1,7 @@ +@props([ + 'name', +]) + + + Hello {{ $name }} + diff --git a/tests/Integration/View/templates/varied-dynamic-calls.blade.php b/tests/Integration/View/templates/varied-dynamic-calls.blade.php new file mode 100644 index 000000000000..5b267ca4d906 --- /dev/null +++ b/tests/Integration/View/templates/varied-dynamic-calls.blade.php @@ -0,0 +1,2 @@ + +