1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Implement DefinitionBook as MutableConfigurable

This is a slightly more correct implementation, but perhaps not worth
the headache.
This commit is contained in:
Aidan Woods 2020-05-05 19:09:57 +01:00
parent 0ef406e6d2
commit c835535176
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 10 additions and 11 deletions

View File

@ -43,9 +43,7 @@ final class Reference implements StateUpdatingBlock
'title' => isset($matches[3]) ? $matches[3] : null, 'title' => isset($matches[3]) ? $matches[3] : null,
]; ];
$State = $State->setting( $State->get(DefinitionBook::class)->mutatingSet($id, $Data);
$State->get(DefinitionBook::class)->setting($id, $Data)
);
return new self($State); return new self($State);
} }

View File

@ -2,12 +2,12 @@
namespace Erusev\Parsedown\Configurables; namespace Erusev\Parsedown\Configurables;
use Erusev\Parsedown\Configurable; use Erusev\Parsedown\MutableConfigurable;
/** /**
* @psalm-type _Data=array{url: string, title: string|null} * @psalm-type _Data=array{url: string, title: string|null}
*/ */
final class DefinitionBook implements Configurable final class DefinitionBook implements MutableConfigurable
{ {
/** @var array<string, _Data> */ /** @var array<string, _Data> */
private $book; private $book;
@ -29,14 +29,10 @@ final class DefinitionBook implements Configurable
/** /**
* @param string $id * @param string $id
* @param _Data $data * @param _Data $data
* @return self
*/ */
public function setting($id, array $data) public function mutatingSet($id, array $data): void
{ {
$book = $this->book; $this->book[$id] = $data;
$book[$id] = $data;
return new self($book);
} }
/** /**
@ -51,4 +47,9 @@ final class DefinitionBook implements Configurable
return null; return null;
} }
public function isolatedCopy(): self
{
return new self($this->book);
}
} }