mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 09:02:44 +02:00
Add StateStoreViewModel and publisher extensions for convenienec.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension Publisher {
|
||||
|
||||
func sinkDispatchTo<S, SA, IA>(_ store: StateStoreViewModel<S, SA, IA>) where SA == Output, Failure == Never {
|
||||
return self
|
||||
.subscribe(on: DispatchQueue.main)
|
||||
.sink { [weak store] (output) in
|
||||
guard let store = store else { return }
|
||||
store.dispatch(action: output)
|
||||
}
|
||||
.store(in: &store.cancellables)
|
||||
}
|
||||
|
||||
|
||||
func dispatchTo<S, SA, IA>(_ store: StateStoreViewModel<S, SA, IA>) -> Publishers.HandleEvents<Publishers.SubscribeOn<Self, DispatchQueue>> where SA == Output, Failure == Never {
|
||||
return self
|
||||
.subscribe(on: DispatchQueue.main)
|
||||
.handleEvents(receiveOutput: { [weak store] action in
|
||||
guard let store = store else { return }
|
||||
store.dispatch(action: action)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user