2017-02-07 00:54:22 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
class PreviewToolReducer {
|
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-04-30 10:25:15 +03:00
|
|
|
func reduce(_ pair: Pair) -> Pair {
|
|
|
|
var state = pair.state.payload
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
switch pair.action {
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case .refreshNow:
|
|
|
|
state.preview = PreviewUtils.state(for: pair.state.uuid,
|
|
|
|
baseUrl: self.baseServerUrl,
|
|
|
|
buffer: state.currentBuffer)
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .reverseSearch(to:position):
|
|
|
|
state.preview.previewPosition = position
|
|
|
|
state.preview.ignoreNextReverse = false
|
|
|
|
state.preview.ignoreNextForward = true
|
|
|
|
state.preview.forceNextReverse = true
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .scroll(to:position):
|
|
|
|
state.preview.previewPosition = position
|
|
|
|
state.preview.ignoreNextReverse = false
|
|
|
|
state.preview.ignoreNextForward = true
|
|
|
|
state.preview.forceNextReverse = false
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .setAutomaticReverseSearch(to:value):
|
|
|
|
state.previewTool.isReverseSearchAutomatically = value
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .setAutomaticForwardSearch(to:value):
|
|
|
|
state.previewTool.isForwardSearchAutomatically = value
|
2017-02-09 02:31:49 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .setRefreshOnWrite(to:value):
|
|
|
|
state.previewTool.isRefreshOnWrite = value
|
2017-02-09 02:31:49 +03:00
|
|
|
|
|
|
|
}
|
2017-04-30 10:25:15 +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
|
|
|
}
|