Swiftpack.co - wotjd/IsolatedStateReactor as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by wotjd.
wotjd/IsolatedStateReactor 1.0.0
A simple isolated state implementation for ReactorKit
⭐️ 3
🕓 2 years ago
iOS macOS watchOS tvOS
.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: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

2 years 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