Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapshots in aggregate partials #406

Merged
merged 5 commits into from
Oct 2, 2023
Merged

Conversation

sonja-turo
Copy link

This pull request is an attempted, updated fix for issue #307 where the states of partials are not restored when a snapshot is retrieved.

This update works by defining a single key (default __esPartials) in the event sourcing config file that is used as a key in the state of a snapshot. Each partial is then reflected for public properties, and a key that is the classname of the partial is added to the __esPartials in the generated. The value of that key is the state of the partial.

This will generate a snapshot state of:

$state = [
    'foo' => 'bar',
    '__esPartials' => [
        'App/Partials/FooPartial' => [
            'fooProperty1' => 1,
            'fooProperty2' => true
    ],
];

Reconstitution of the snapshot goes through each key of __esPartials and matches to a resolved Partial Class, and sets the state of that Partials.

@sonja-turo sonja-turo marked this pull request as ready for review April 24, 2023 22:17
@sebastiandedeyne
Copy link
Member

Looks good! One thing I'd consider changing is removing the partials key altogether. Slashes can't be used for PHP properties anyway, so there won't be a clash in property names. Might as well keep it flat then.

$state = [
    'foo' => 'bar',
    'App\Partials\FooPartial' => [
        'fooProperty1' => 1,
        'fooProperty2' => true
    ],
];

@sonja-turo
Copy link
Author

The unneeded _esPartials key has been removed.

@sonja-turo
Copy link
Author

@sebastiandedeyne Just a little bump.

@sebastiandedeyne sebastiandedeyne merged commit b891874 into spatie:main Oct 2, 2023
@sebastiandedeyne
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants