Skip to content

Commit

Permalink
WIP: Update to Livewire 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Siewertsen committed Sep 28, 2020
1 parent 422a8f9 commit 30ea8d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php": "^7.4",
"illuminate/support": "^7.0",
"statamic/cms": "3.0.*",
"livewire/livewire": "^1.0"
"livewire/livewire": "^2.0"
},
"extra": {
"statamic": {
Expand Down
15 changes: 9 additions & 6 deletions src/Tags/Livewire.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function wildcard($expression)
*/
$parameter = $this->params;

/**
* Let the Livewire magic happen.
*/
$lastArg = trim(last(explode(',', $expression)));

if (Str::startsWith($lastArg, 'key(') && Str::endsWith($lastArg, ')')) {
Expand All @@ -35,19 +38,19 @@ public function wildcard($expression)
$cachedKey = "'" . Str::random(7) . "'";
}

if (!isset($_instance)) {
$dom = \Livewire\Livewire::mount($expression, $parameter->toArray())->dom;
if (! isset($_instance)) {
$html = \Livewire\Livewire::mount($expression, $parameter->toArray())->html();
} elseif ($_instance->childHasBeenRendered($cachedKey)) {
$componentId = $_instance->getRenderedChildComponentId($cachedKey);
$componentTag = $_instance->getRenderedChildComponentTagName($cachedKey);
$dom = \Livewire\Livewire::dummyMount($componentId, $componentTag);
$html = \Livewire\Livewire::dummyMount($componentId, $componentTag);
$_instance->preserveRenderedChild($cachedKey);
} else {
$response = \Livewire\Livewire::mount($expression, $parameter->toArray());
$dom = $response->dom;
$_instance->logRenderedChild($cachedKey, $response->id, \Livewire\Livewire::getRootElementTagName($dom));
$html = $response->html();
$_instance->logRenderedChild($cachedKey, $response->id(), \Livewire\Livewire::getRootElementTagName($html));
}
return $dom;
return $html;
}

/**
Expand Down

0 comments on commit 30ea8d6

Please sign in to comment.