From c8355351768d451a00ef4a2ca85fdd2ab85aefa3 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 5 May 2020 19:09:57 +0100 Subject: [PATCH] Implement DefinitionBook as MutableConfigurable This is a slightly more correct implementation, but perhaps not worth the headache. --- src/Components/Blocks/Reference.php | 4 +--- src/Configurables/DefinitionBook.php | 17 +++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Components/Blocks/Reference.php b/src/Components/Blocks/Reference.php index ef0a560..6570de1 100644 --- a/src/Components/Blocks/Reference.php +++ b/src/Components/Blocks/Reference.php @@ -43,9 +43,7 @@ final class Reference implements StateUpdatingBlock 'title' => isset($matches[3]) ? $matches[3] : null, ]; - $State = $State->setting( - $State->get(DefinitionBook::class)->setting($id, $Data) - ); + $State->get(DefinitionBook::class)->mutatingSet($id, $Data); return new self($State); } diff --git a/src/Configurables/DefinitionBook.php b/src/Configurables/DefinitionBook.php index 0c22538..38e55b0 100644 --- a/src/Configurables/DefinitionBook.php +++ b/src/Configurables/DefinitionBook.php @@ -2,12 +2,12 @@ namespace Erusev\Parsedown\Configurables; -use Erusev\Parsedown\Configurable; +use Erusev\Parsedown\MutableConfigurable; /** * @psalm-type _Data=array{url: string, title: string|null} */ -final class DefinitionBook implements Configurable +final class DefinitionBook implements MutableConfigurable { /** @var array */ private $book; @@ -29,14 +29,10 @@ final class DefinitionBook implements Configurable /** * @param string $id * @param _Data $data - * @return self */ - public function setting($id, array $data) + public function mutatingSet($id, array $data): void { - $book = $this->book; - $book[$id] = $data; - - return new self($book); + $this->book[$id] = $data; } /** @@ -51,4 +47,9 @@ final class DefinitionBook implements Configurable return null; } + + public function isolatedCopy(): self + { + return new self($this->book); + } }