Skip to content

Commit

Permalink
fix: raise props priority over internal state
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Apr 17, 2023
1 parent cde5af2 commit 6a05fce
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
*/
class UI
{


/**
* Initialize Leaf UI on a page
* @return string
*/
public static function init(): string
{
return (
implode(Core::$scripts) .
return (implode(Core::$scripts) .
static::createElement('script', [
'src' => '/vendor/leafs/ui/client/dist/ui.cjs.production.min.js',
], [''])
Expand Down Expand Up @@ -103,7 +100,11 @@ public static function component(string $component, array $props = []): string
$component = new $component;

if (!$component->key) {
$component->key = $props['key'] ?? Utils::randomId($component::class);
$component->key = Utils::randomId($component::class);
}

if ($props['key'] ?? false) {
$component->key = $props['key'];
}

Core::$state[$component->key] = array_merge(get_class_vars($component::class), Core::$state[$component->key] ?? [], ['key' => $component->key], $props);
Expand Down

0 comments on commit 6a05fce

Please sign in to comment.