ReSwift v4.0.0 Release Notes

Release Date: 2017-04-20 // about 7 years ago
  • Breaking API Changes:

    Introduced a new Subscription API (#203) - @Ben-G, @mjarvis, @DivineDominion

    The subscription API provides basic operators, such as skipRepeats (skip calls to newState unless state value changed) and select (sub-select a state).

    This is a breaking API change that requires migrating existing subscriptions that sub-select a portion of a store's state:

    - 
    

    Subselecting state in 3.0.0:

    store.subscribe(subscriber) { ($0.testValue, $0.otherState?.name) }
    
    - 
    

    Subselecting state in 4.0.0:

    store.subscribe(subscriber) { $0.select { ($0.testValue, $0.otherState?.name) } }
    

    0️⃣ For any store state that is Equatable or any sub-selected state that is Equatable, skipRepeats will be used by default.

    For states/substates that are not Equatable, skipRepeats can be implemented via a closure:

    store.subscribe(subscriber) { $0.select { $0.testValue }.skipRepeats { return $0 == $1 } }
    

    ⬇️ Reducer type has been removed in favor of reducer function (#177) - Ben-G

    👀 Here's an example of a new app reducer, for details see the README:

    func counterReducer(action: Action, state: AppState?) -\> AppState { var state = state ?? AppState() switch action { case \_ as CounterActionIncrease: state.counter += 1case \_ as CounterActionDecrease: state.counter -= 1default:break } return state }
    

    dispatch functions now return Void instead of Any (#187) - @Qata

    - The return type has been removed without any replacement, since the core team did not find any use cases of it. A common usage of the return type in redux is returning a promise that is fullfilled when a dispatched action is processed. While it's generally discouraged to disrupt the unidirectional data flow using this mechanism we do provide a dispatch overload that takes a callback argument and serves this purpose.

    👉 Make dispatch argument in middleware non-optional (#225) - @dimazen, @mjarvis, @Ben-G

    Middleware now has a generic type parameter that is used for the getState method and matches the Store's State type. This allows accessing the state in middleware code without type casting (#226) - @mjarvis

    Other:

    • Extend StoreType with substate selector subscription (#192) - @mjarvis
    • ➕ Add DispatchingStoreType protocol for testing (#197) - @mjarvis
    • 📦 Installation guide for Swift Package Manager - @thomaspaulmann
    • 📚 Update documentation to reflect breaking API changes - @mjarvis
    • Clarify error message on concurrent usage of ReSwift - @langford