danbee / persephone

macOS MPD client written in Swift.
https://persephone.fm
MIT License
219 stars 19 forks source link

transition MPDReducer to middleware #32

Closed DivineDominion closed 5 years ago

DivineDominion commented 5 years ago

Your crash report on Slack showed that the reducer only produces side effects and referenced App.store.state during the initialization, maybe resulting in an infinite loop of sorts.

Since this is all just side effect, I pulled it into a Middleware that does sit outside the reducer setup, and executed after using all reducers to process the action, e.g. after ReSwiftInit.

This could fix the problem.


In general, I would reconsider dispatching actions through the store for these and call MPDClient methods directly. You're using the ReSwift stack not to affect app state here, but to have a unified event queue/event bus of sorts. Maybe here's potential for affecting app state, e.g. set MPDState.isPlaying = true and making sure a subscriber starts/stops mpd playback accordingly. Then remote controlling the mpd service would be a projection of the pure state. Could also go horribly wrong :)