ReSwift
ReSwift copied to clipboard
Behavior of skipRepeats unintuitive
If i explicitly define a skipRepeats
function on my subscription selection I feel that it should take precedence over my type's ==
implementation. More than a few times I've been burned by not realizing the Subscription
is forgoing skipRepeats
because its selection is Equatable
.
That doesn't sound like what I'd expect to happen, but I'm not using skipRepeats at all myself. So could you illustrate the issue with minimal breaking code? What do you write, what do you expect to happen, what happens instead?
say i subscribe to the store
store.subscribe(self) {
$0.select {
$0
}.skipRepeats({ (old, new) -> Bool in
return old.activeProject == new.activeProject
})
}
If my AppState
is Equatable
and I have ==
return true, than the skipRepeats
closure is not called. If I make ==
return false than it will be called. I think that if I remove the Equatable
conformance of AppState
than it might also call the skipRepeats
closure but I haven't tried that because too much would break.
It seems that the current behavior is that if the type is Equatable
and if ==
returns true than skipRepeats
closure is never called.
Aha, now I understand -- there's two skipRepeats
, one invisible. Your best bet for now is to deactivate skipRepeats for equatable states upon store initialization.
This is related to #259 and not yet fixed.
A solution as per #259 could be to return an AutoSkipRepeats<S>
type from select
that ditches its own equatability check once the user invokes skipRepeats
.
Any solutions to this?
I've been thinking about this and maybe I'm missing something, but the second skipRepeats
will always return true if the app's state doesn't change, right? Unless you're introducing a side effect in the selector function, which should be pure.
Do you have a case where the app's state doesn't change and a selection of parts of the substate could yield a different result?