Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducer-based state management experiment (using Mobius.swift) #5866

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

acb-mv
Copy link
Contributor

@acb-mv acb-mv commented Feb 26, 2024

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 Reviewable

…er, wire applicationBecameActive through Mobius
@acb-mv acb-mv added the iOS Issues related to iOS label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant