Middleware for action side effects in Swidux using “Watchmen“ 🙂
Create a Watchmen
that could react to some actions to handle side effects and then dispatch other actions.
let doomsdayClockWatchmen = Watchmen { action in
switch action {
case DoomsdayClockAction.fetchDoomsdayClock:
fetchDoomsdayClock {
store.dispatch(DoomsdayClockAction.fetchDoomsdayClockSuccess(clock: $0))
}
default: break
}
}
Add your watchmen to your Store
middlewares.
import Swidux
import SwiduxWatchmen
let store = Store<AppState>(
initialState: AppState(),
reducer: reducer,
middlewares: [
.create(combiningWatchmen: [ doomsdayClockWatchmen ]),
]
)
Add the following dependency to your Cartfile
:
github "clmntcrl/swidux-watchmen" ~> 0.2
Add the following pod to your Podfile
:
pod 'SwiduxWatchmen', '~> 0.2'
Add the package as dependency in your Package.swift
:
dependencies: [
.package(url: "https://github.com/clmntcrl/swidux-watchmen.git", from: "0.2.0"),
]
SwiduxWatchmen is released under the MIT license. See LICENSE for details.