1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00
vimr/VimR/PreviewToolReducer.swift

57 lines
1.6 KiB
Swift
Raw Normal View History

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> {
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)
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
case let .scroll(to:position):
state.preview.previewPosition = position
2017-03-31 09:05:42 +03:00
state.preview.ignoreNextReverse = false
state.preview.ignoreNextForward = true
2017-02-12 18:40:49 +03:00
state.preview.forceNextReverse = false
case let .setAutomaticReverseSearch(to:value):
state.previewTool.isReverseSearchAutomatically = value
case let .setAutomaticForwardSearch(to:value):
state.previewTool.isForwardSearchAutomatically = value
case let .setRefreshOnWrite(to:value):
state.previewTool.isRefreshOnWrite = value
}
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
}