Skip to content

Instantly share code, notes, and snippets.

@twittemb
Created July 15, 2018 18:22
Show Gist options
  • Select an option

  • Save twittemb/54b5d63abfd557813fba03b9b8cb2f65 to your computer and use it in GitHub Desktop.

Select an option

Save twittemb/54b5d63abfd557813fba03b9b8cb2f65 to your computer and use it in GitHub Desktop.
public func dispatch (action: Action) {
// every received action is converted to an async action
action
.toAsync()
.map { [unowned self] (action) -> StateType? in
return self.reducers.reduce(self.state.value, { (state, reducer) -> StateType? in
return reducer(state, action)
})
}.subscribe(onNext: { [unowned self] (newState) in
self.state.accept(newState)
}).disposed(by: self.disposeBag)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment