Last active
September 12, 2017 14:10
-
-
Save thiagomarini/264e71c7f2b853f5fbd6e4c44ee0dc53 to your computer and use it in GitHub Desktop.
Usage in a nutshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$reducers = [ | |
'create' => [ | |
'1.0' => function (array $currentState, array $actionData): ?array { | |
# Calculate new state in here. | |
# Things you should never do inside a reducer: | |
# - Mutate its arguments; | |
# - Perform side effects like API calls and routing transitions; | |
# - Call non-pure functions, e.g. $object->method(); | |
return $actionData; | |
} | |
] | |
]; | |
// pass reducers to store | |
$store = new Store($reducers); | |
// dispatch events | |
$currentState = $store->dispatch(new Event()); | |
// hydrate the aggregate root | |
$shipment = Shipment::fromState($currentState); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment