jcombee / reduced
A php library for managing state.
dev-main
2022-05-14 13:22 UTC
Requires
- php: ^8.1
Requires (Dev)
- pestphp/pest: ^1.21
- pestphp/pest-plugin-mock: ^1.0
This package is auto-updated.
Last update: 2024-12-14 19:09:47 UTC
README
A state management library for PHP.
Content
Instalation
composer require jcombee/reduced
How to use
This example bellow uses the classes in: tests/Example.
$state = new LocationState(0, 0); $store = new Store($state); $store->subscribe(function (LocationState $state) { echo "Location: {$state->x}, {$state->y}"; }); $store->registerReducer(new MovementReducer()); $store->dispatch(new MovementAction(DirectionEnum::UP)); $store->dispatch(new MovementAction(DirectionEnum::LEFT)) $store->dispatch(new MovementAction(DirectionEnum::DOWN)) $store->dispatch(new MovementAction(DirectionEnum::RIGHT)) $state = $store->getState(); /** * Location: 0, -1 * Location: -1, -1 * Location: -1, 0 * Location: 0, 0 */