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

Version 1: New API #40

Merged
merged 1 commit into from
Dec 31, 2023
Merged

Version 1: New API #40

merged 1 commit into from
Dec 31, 2023

Conversation

MaximBazarov
Copy link
Owner

Public API revamp, provide a way of multiple wrappers be stacked.

@ObservableValue
@RemoteValue(.backend(.getUserName))
@Persistent(.secure("com.user.name"))
var str = "str-default"

Also changing the mutability:

@SwiftUIBind(
    \Storage.$str,
     mutate: UpdateStr.self
) var str

So @Mutable wrapper is removed, instead, decisions are the only way to mutate the state.

UpdateStr is a special type of decision, that takes a newValue as a parameter:

struct UpdateStr: ValueDecision {
    var newValue: String

    func mutate(_ env: Decide.DecisionEnvironment) {
        env[\.Storage.$str] = newValue
    }
}

this way the mutability is expressed explicitly and gives ability to combine other decisions and side effects on value updates.

Verbosity: right now this version requires quite a sophisticated code to be written, e.g. SwiftUIBind, later the plan is to utilise swift macros to write this code for the user.

@MaximBazarov MaximBazarov merged commit ffc2901 into main Dec 31, 2023
1 check passed
@MaximBazarov MaximBazarov deleted the state-management-revamp branch December 31, 2023 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant