Skip to content

Instantly share code, notes, and snippets.

@thiagomarini
Last active September 12, 2017 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomarini/264e71c7f2b853f5fbd6e4c44ee0dc53 to your computer and use it in GitHub Desktop.
Save thiagomarini/264e71c7f2b853f5fbd6e4c44ee0dc53 to your computer and use it in GitHub Desktop.
Usage in a nutshell
<?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