Cedux: Experimenting with the Redux Model in C
Created on 2022-12-19T11:50:40-06:00
Article is for a hobbyist attempt at reproducing the Redux javascript framework in the C language. It also hilariously functions as a simple explanation of how Redux works which is much simpler than the Redux website.
Store: the root of a tree of values for the program.
Action: an object (command pattern) describing what to be done to the program state.
Reducer: a function which interprets the command and creates a copy of the sub-tree with newly updated data.
Dispatch: sending an action to a store and running the relevant reducers.
Whenever a subtree is modified then you have to clone the modified subtree and any higher trees (as the pointer has to be changed thus that tree is now out of date and must be copied as well.) Unchanged values which can be accessed by-reference can have their references copied as-is.
Redux has a library called "immer" to fake mutability. What the library does is record all attempts to write state to a tape. Then the tape is used to make appropriate copies of subtrees to build the new world state.