Skip to content

Commit

Permalink
Merge pull request #190 from spatie/revert-179-livewire-3
Browse files Browse the repository at this point in the history
Revert "Provide Livewire 3 context"
  • Loading branch information
rubenvanassche authored Apr 26, 2024
2 parents 709a51a + 95532da commit 3400ed6
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions src/ContextProviders/LaravelLivewireRequestContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Livewire\LivewireManager;
use Livewire\Mechanisms\ComponentRegistry;

class LaravelLivewireRequestContextProvider extends LaravelRequestContextProvider
{
Expand Down Expand Up @@ -41,26 +40,6 @@ public function toArray(): array
/** @return array<string, mixed> */
protected function getLivewireInformation(): array
{
if ($this->request->has('components')) {
$data = [];

foreach ($this->request->get('components') as $component) {
$snapshot = json_decode($component['snapshot'], true);

$class = app(ComponentRegistry::class)->getClass($snapshot['memo']['name']);

$data[] = [
'component_class' => $class ?? null,
'data' => $snapshot['data'],
'memo' => $snapshot['memo'],
'updates' => $this->resolveUpdates($component['updates']),
'calls' => $component['calls'],
];
}

return $data;
}

/** @phpstan-ignore-next-line */
$componentId = $this->request->input('fingerprint.id');

Expand All @@ -77,17 +56,12 @@ protected function getLivewireInformation(): array
$componentClass = null;
}

/** @phpstan-ignore-next-line */
$updates = $this->request->input('updates') ?? [];

return [
[
'component_class' => $componentClass,
'component_alias' => $componentAlias,
'component_id' => $componentId,
'data' => $this->resolveData(),
'updates' => $this->resolveUpdates($updates),
],
'component_class' => $componentClass,
'component_alias' => $componentAlias,
'component_id' => $componentId,
'data' => $this->resolveData(),
'updates' => $this->resolveUpdates(),
];
}

Expand All @@ -112,8 +86,11 @@ protected function resolveData(): array
}

/** @return array<string, mixed> */
protected function resolveUpdates(array $updates): array
protected function resolveUpdates(): array
{
/** @phpstan-ignore-next-line */
$updates = $this->request->input('updates') ?? [];

return array_map(function (array $update) {
$update['payload'] = Arr::except($update['payload'] ?? [], ['id']);

Expand Down

0 comments on commit 3400ed6

Please sign in to comment.