jcombee/reduced

A php library for managing state.

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/jcombee/reduced

dev-main 2022-05-14 13:22 UTC

This package is auto-updated.

Last update: 2025-10-14 21:12:27 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
     */