4 ms·
Yes - you've just described a reducer function (ala Redux and React's `useReducer`). Note that to be a _true_ Finite State Machine, the reducer function would
by acemarke 4y ago
Yes - you've just described a reducer function (ala Redux and React's `useReducer`).
Note that to be a _true_ Finite State Machine, the reducer function would need to be written to first check what state value it's currently in, _then_ decide if the input is relevant. Most Redux reducers are not actually written that way - they just update the state value based on the action, regardless of what the existing state was.
References:
- https://redux.js.org/style-guide/#treat-reducers-as-state-machines https://redux.js.org/style-guide/#treat-reducers-as-state-ma...
- https://dev.to/davidkpiano/redux-is-half-of-a-pattern-1-2-1hd7 https://dev.to/davidkpiano/redux-is-half-of-a-pattern-1-2-1h...
(source: I maintain Redux, and that Redux style guide entry and the additional blog post were written by David Khourshid, who is an expert on state machines.)
- davidkpiano 4y agoYep, the "stateless" part of the state machine is its transition function.
- proc0 4y agoI think the idea there is to think of all the actions as transitions in a state machine, however the state machine itself is the high level concept and not the implementation. A reducer function does not keep state, therefore not a state machine.