Created
May 15, 2024 14:16
-
-
Save DanielCoulbourne/17b8c4db9a938245dc1a9b754281a4d9 to your computer and use it in GitHub Desktop.
A Livewire Synth for Verbs States
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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