Reducer-based state management experiment (using Mobius.swift) #5866
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an experimental sketch, and is not intended to be merged or shipped, It is a proof of concept of integrating a reducer-based effect-management methodology into the app, specifically the TunnelManager class (though it should be portable). It is currently in a very preliminary state, but will be expanded.
The problem: We have classes which have state and produce effects, and which are fiddly to test. This is because effects are produced as side-effects, with the logic for determining effects and state mutations being interleaved throughout the codebase.
The solution: refactor the logic to be tested into a reducer-based functional-reactive methodology, in which business logic is isolated into a reducer function without side-effects, and inputs (Events) and outputs (Effects) are modelled as types. The reducer function takes the current state and an incoming Event, and produces an updated state and zero or more Effects. The Effects are subsequently put into action by an effect router, though this is separate from the reducer function, which, being pure, can be tested in isolation.
Decisions: A number of functional reactive/reducer-based frameworks for iOS exist, perhaps most notably among them, The Composable Architecture. Another one, and the one I chose, is Mobius, an open-source framework developed at Spotify. I chose Mobius for this experiment because it has implementations with similar APIs for both iOS (Mobius.swift) and Android (the Java-based version), which would allow the keeping of logic in sync between the two mobile implementations to be made easier.
This change is