Swiftpack.co - wotjd/IsolatedStateReactor as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
wotjd/IsolatedStateReactor
A simple isolated state implementation for ReactorKit
.package(url: "https://github.com/wotjd/IsolatedStateReactor.git", from: "1.0.0")

IsolatedStateReactor

A simple isolated state implementation for ReactorKit

Previously,

distinctUntilChanged operator follows state observable and this produces quiet complicated code.

for example,

// in bind(reactor:)
reactor.state.map(\.someBoolState)
  .distinctUntilChanged()
  ...
// in reactor.mutate(action:)
// to avoid skipping event by distinctUntilChanged
return Observable.of(true, false).map(Mutation.updateBoolState)

isolatedState

to solve this, I made isolatedState

// usage
reactor.isolatedState(\.boolProperty)
  // work properly without distinctUntilChanged()
  .subscribe(...)
  
// implementation
class ViewReactor: IsolatedStateReactor {
  enum Action { ... }
  enum Mutation { ... }
  // State should provide updates stores keyPath array to know which property is updated by mutation
  struct State: UpdateStorable {
    var boolProperty = false
    
    var updates: [PartialKeyPath<Self>] = [\State.self]
  }

  func mutate(action: Action) -> Observable<Mutation> { ... }
  func reduce(isolatedState: inout IsolatedState, mutation: Mutation) {
    switch mutation {
    case let .updateBoolProperty(bool):
      state.boolProperty = bool
    }
  }
}

GitHub

link
Stars: 3
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Dependencies

Release Notes

3 weeks ago
  • implement IsolatedStateReactor
    • checks update of each property on state of Reactor (with simple KeyPath array)
    • allows subscription of separated state property stream without distinctUntilChanged operation
  • supports Swift Package Manager
  • add demo project (import locally)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics