Skip to content

Commit

Permalink
Update OnChange.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Aug 14, 2023
1 parent f0c697b commit f62ba37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/ComposableArchitecture/Reducer/Reducers/OnChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Reducer {
removeDuplicates isDuplicate: @escaping (V, V) -> Bool,
@ReducerBuilder<State, Action> _ reducer: @escaping (_ oldValue: V, _ newValue: V) -> R
) -> _OnChangeReducer<Self, V, R> {
_OnChangeReducer(base: self, toValue: toValue, predicate: predicate, reducer: reducer)
_OnChangeReducer(base: self, toValue: toValue, isDuplicate: isDuplicate, reducer: reducer)
}

/// Adds a reducer to run when this reducer changes the given value in state.
Expand Down Expand Up @@ -107,7 +107,7 @@ extension Reducer {
of toValue: @escaping (State) -> V,
@ReducerBuilder<State, Action> _ reducer: @escaping (_ oldValue: V, _ newValue: V) -> R
) -> _OnChangeReducer<Self, V, R> {
_OnChangeReducer(base: self, toValue: toValue, predicate: ==, reducer: reducer)
_OnChangeReducer(base: self, toValue: toValue, isDuplicate: ==, reducer: reducer)
}
}

Expand All @@ -120,7 +120,7 @@ where Base.State == Body.State, Base.Action == Body.Action {
let toValue: (Base.State) -> Value

@usableFromInline
let predicate: (Value, Value) -> Bool
let isDuplicate: (Value, Value) -> Bool

@usableFromInline
let reducer: (Value, Value) -> Body
Expand All @@ -129,12 +129,12 @@ where Base.State == Body.State, Base.Action == Body.Action {
init(
base: Base,
toValue: @escaping (Base.State) -> Value,
predicate: @escaping (Value, Value) -> Bool,
isDuplicate: @escaping (Value, Value) -> Bool,
reducer: @escaping (Value, Value) -> Body
) {
self.base = base
self.toValue = toValue
self.predicate = predicate
self.isDuplicate = isDuplicate
self.reducer = reducer
}

Expand All @@ -143,7 +143,7 @@ where Base.State == Body.State, Base.Action == Body.Action {
let oldValue = toValue(state)
let baseEffects = self.base.reduce(into: &state, action: action)
let newValue = toValue(state)
return predicate(oldValue, newValue)
return isDuplicate(oldValue, newValue)
? baseEffects
: .merge(baseEffects, self.reducer(oldValue, newValue).reduce(into: &state, action: action))
}
Expand Down

0 comments on commit f62ba37

Please sign in to comment.