2017-02-07 00:54:22 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-03-29 21:10:11 +03:00
|
|
|
class PreviewToolReducer: Reducer {
|
2017-02-07 00:54:22 +03:00
|
|
|
|
|
|
|
typealias Pair = StateActionPair<UuidState<MainWindow.State>, PreviewTool.Action>
|
|
|
|
|
2017-02-12 13:24:15 +03:00
|
|
|
init(baseServerUrl: URL) {
|
|
|
|
self.baseServerUrl = baseServerUrl
|
|
|
|
}
|
|
|
|
|
2017-03-29 21:17:45 +03:00
|
|
|
func reduce(_ source: Observable<Pair>) -> Observable<Pair> {
|
2017-02-09 02:31:49 +03:00
|
|
|
return source.map { pair in
|
|
|
|
var state = pair.state.payload
|
|
|
|
|
|
|
|
switch pair.action {
|
|
|
|
|
|
|
|
case .refreshNow:
|
2017-02-12 13:24:15 +03:00
|
|
|
state.preview = PreviewUtils.state(for: pair.state.uuid,
|
|
|
|
baseUrl: self.baseServerUrl,
|
|
|
|
buffer: state.currentBuffer)
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
case let .reverseSearch(to:position):
|
2017-02-12 13:24:15 +03:00
|
|
|
state.preview.previewPosition = position
|
2017-03-31 09:05:42 +03:00
|
|
|
state.preview.ignoreNextReverse = false
|
2017-02-12 13:24:15 +03:00
|
|
|
state.preview.ignoreNextForward = true
|
2017-02-12 18:40:49 +03:00
|
|
|
state.preview.forceNextReverse = true
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
case let .scroll(to:position):
|
2017-02-11 20:32:22 +03:00
|
|
|
state.preview.previewPosition = position
|
2017-03-31 09:05:42 +03:00
|
|
|
state.preview.ignoreNextReverse = false
|
2017-02-11 20:32:22 +03:00
|
|
|
state.preview.ignoreNextForward = true
|
2017-02-12 18:40:49 +03:00
|
|
|
state.preview.forceNextReverse = false
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
case let .setAutomaticReverseSearch(to:value):
|
2017-02-11 20:32:22 +03:00
|
|
|
state.previewTool.isReverseSearchAutomatically = value
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
case let .setAutomaticForwardSearch(to:value):
|
2017-02-11 20:32:22 +03:00
|
|
|
state.previewTool.isForwardSearchAutomatically = value
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
case let .setRefreshOnWrite(to:value):
|
2017-02-11 20:32:22 +03:00
|
|
|
state.previewTool.isRefreshOnWrite = value
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
|
|
|
|
}
|
2017-02-07 00:54:22 +03:00
|
|
|
}
|
2017-02-12 13:24:15 +03:00
|
|
|
|
|
|
|
fileprivate let baseServerUrl: URL
|
2017-02-07 00:54:22 +03:00
|
|
|
}
|