I am building an application with React / Redux that is somewhat similar to a text editor. This is not a text editor, but the same general paradigm. There is a cursor to place new items. Items can be added, selected, deleted, etc.
I'm struggling to structure my gearboxes in a way that matches the spirit of redux. I have separate state slices representing the state of the selection, the text itself, the state of the cursor, and other settings. I think the redux approach will have reducers for each of these state slices, independently changing state in response to the action.
However, in a text editor, these sections of the state are much more complicated than at first glance. When you press a key, sometimes a letter is added at the cursor location, and the cursor moves forward. However, if text is selected, the selected text will be deleted first. If you are in insert mode, the text on the right will be consumed. Or, perhaps the modifier key does not work, and the text is not added at all.
In other words, different sections of the state are very connected, and what happens in one depends on the current state of the others.
I read the “Beyond Combine Reducers” section of the Redux manual and know how to share the state between the slice reducers, but this seems inelegant if the end result passes all the state to each slice reducer. Another thing that I do not like about his approach is that each gearbox will have to look at the general condition and independently come to the same conclusion about what should be its correct answer to a specific action. Is this what I should do, or should I somehow structure my condition?
An alternative to a single centralized reducer indicating the cursor, selection state, content, etc., how to mutate is easier conceptually, but does not seem to scale very well.
I also read that many times the bound state is a sign that your state is not minimal and that you should restructure and use memoized selectors. However, this does not seem to be the case. The cursor position is not inferred from the text and is not a selection state.
Finally, I also looked at Thunk middleware, as this is what I saw offered for handling several / more complex actions. I do not dare, because it seems that it is more intended for asynchronous sending, and this is not so.
I would like to understand the right approach for developing this type of application, which is most consistent with the "redux" design pattern and understand any trade-offs that may exist if there are several ways forward.