hirethunk / verbs

Verbs is an event sourcing package for PHP artisans
https://verbs.thunk.dev
MIT License
412 stars 32 forks source link

Fix event state property loading #174

Closed joshhanley closed 2 weeks ago

joshhanley commented 2 weeks ago

PR #169 added support for using states directly as properties on events.

But there is an issue when multiple events, that are applied to different states, are fired one after another where all subsequent events were being applied to the first state instead of the correct state.

This is because in the EventStateRegistry we are memoizing the properties loaded from the event, similar to how attributes are being loaded and memoized.

But the issue is that attributes don't have state, so can be memoized based on the event class. This doesn't work for properties as they do actually have state, as such the load state was being returned from the memoized properties.

So this PR fixes it by ensuring the memoization for properties is scoped to the event ID as well as the event class and adds tests.