1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-28 08:13:17 +03:00
vimr/VimR/PreviewToolTransformer.swift
2017-02-12 10:54:01 +01:00

49 lines
1.2 KiB
Swift

/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
import CocoaMarkdown
import RxSwift
import CocoaMarkdown
class PreviewToolTransformer: Transformer {
typealias Pair = StateActionPair<UuidState<MainWindow.State>, PreviewTool.Action>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
var state = pair.state.payload
switch pair.action {
case .refreshNow:
return pair
case let .reverseSearch(to:position):
return pair
case .forwardSearch:
return pair
case let .scroll(to:position):
state.preview.previewPosition = position
state.preview.ignoreNextForward = true
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)
}
}
}