jcombee/reduced

用于管理状态的PHP库。

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

This package is auto-updated.

Last update: 2024-09-14 18:31:43 UTC


README

PHP状态管理库。

内容

安装

composer require jcombee/reduced

如何使用

以下示例使用了以下类: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
     */