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
Remove unnecessary State
constraint for reusability
#27
Conversation
thx @inamiy ! However, Your idea is practically correct. |
Oh, I wasn't aware of (For example, in general, |
…ng its shared instance
2eaf9e7 Changed |
@inamiy I still have the following concerns.
|
Minimum type constraint is always the winner of code abstraction and reusability.
As you mentioned, that will be even more counter-intuitive because
True, but moving |
I think that your idea is roughly correct, but I would like to discuss a little more.
You are correct. struct FooState {
var prop: Int = 0
}
struct FooMutations: Mutations {
func commit(action: FooAction, state: FooState) {
var state = state
switch action {
case .increment:
state.prop += 1
}
}
} Since this is standard behavior of Swift, it's acceptable for me, I also think that it might be confusing to users.
Agreed 👍
hmm |
Yes, it makes sense whenever But in essence (as you said), To wrap up, this pull request is just my own perspective of sticking to the simplest types as possible, but I also understand that other users may look this as less consistency because of it's abstractness. |
I want to advance thinking after merging this PR. |
This is just an example code to improve framework's type signatures.
(Note: Test fixes are not included)
State
should not be constrained by any protocols (especially with associated type). Otherwise, it won't be reusable and composable when making a larger state.Action
which should be isolated fromState
.Mutation
should be the protocol that associates bothState
andAction
extension Actions where Action == CounterAction
is more intuitive to make an extension compared toextension Actions where State == CounterState
, whereCounterAction
is implicitly associated insideCounterState
.