Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Jul 29, 2024
1 parent 1cab3b5 commit f35e992
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
17 changes: 17 additions & 0 deletions config/wireuse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@
],
],

/*
|--------------------------------------------------------------------------
| Structure Discovery
|--------------------------------------------------------------------------
|
| This controls structure discovery.
|
| @doc https://github.com/spatie/php-structure-discoverer
|
*/

'scout' => [
'cache_store' => null,

'cache_lifetime' => 60 * 24,
],

];
29 changes: 26 additions & 3 deletions src/Scout/LivewireScout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Foxws\WireUse\Support\Discover\LivewireStructureScout;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Livewire\Livewire;
use Spatie\StructureDiscoverer\Data\DiscoveredStructure;

Expand All @@ -29,12 +30,19 @@ public static function create(

public function register(): void
{
$components = $this->get();

$components->each(fn (array $component) => Livewire::component(...$component));
$this->get()->each(fn (array $component) => Livewire::component(...$component));
}

public function get(): Collection
{
return Cache::store($this->getCacheStore())->remember(
$this->getCacheKey(),
$this->getCacheLifetime(),
fn () => $this->get()
);
}

protected function buildCollection(): Collection
{
$scout = $this->getLivewireStructures();

Expand Down Expand Up @@ -78,4 +86,19 @@ protected function getLivewireStructures(): LivewireStructureScout
->path($this->path)
->prefix("livewire-structures-{$this->prefix}");
}

protected function getCacheKey(): string
{
return "wireuse.scout.livewire.{$this->prefix}";
}

protected function getCacheStore(): ?string
{
return config('wireuse.scout.cache_store');
}

protected function getCacheLifetime(): ?int
{
return config('wireuse.scout.cache_lifetime');
}
}

0 comments on commit f35e992

Please sign in to comment.