Skip to content

Instantly share code, notes, and snippets.

@DanielCoulbourne
Created May 15, 2024 14:16
Show Gist options
  • Save DanielCoulbourne/17b8c4db9a938245dc1a9b754281a4d9 to your computer and use it in GitHub Desktop.
Save DanielCoulbourne/17b8c4db9a938245dc1a9b754281a4d9 to your computer and use it in GitHub Desktop.
A Livewire Synth for Verbs States
<?php
namespace App\Livewire\Synths;
use Livewire\Mechanisms\HandleComponents\Synthesizers\Synth;
use Thunk\Verbs\State;
class StateSynth extends Synth
{
public static $key = 'VrbSt';
public static function match($target)
{
return $target instanceof State;
}
public function dehydrate($target)
{
return [null, [
'id' => $target->id,
'type' => get_class($target),
]];
}
public function hydrate($data, $meta)
{
return $meta['type']::load($meta['id']);
}
public function get(&$target, $key)
{
throw new \Exception('Cannot get state properties directly.');
}
public function set(&$target, $key, $value)
{
throw new \Exception('Cannot set state properties directly.');
}
public function call(&$target, $method, $params, $addEffect)
{
throw new \Exception('Cannot call state methods directly.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment