hirethunk / verbs

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

Register states when reconstituting from events. #151

Closed DanielCoulbourne closed 2 months ago

DanielCoulbourne commented 2 months ago

Previously we didn't register states before reconstituting them from events (like if a snapshot was removed)

If an apply method used $this->state(SomeState::class) it would attempt to reconstitute the state WHILE reconstituting the state (because it didn't find an instance in the cache). This would cause an infinite loop.

This PR just registers the state with the StateInstanceCache before it begins running the hooks so that there is an instance in the cache if any of the hooks require one.