1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00
vimr/VimR/PreviewReducer.swift

60 lines
1.6 KiB
Swift
Raw Normal View History

2017-01-22 16:22:05 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
class MarkdownReducer {
2017-01-22 16:22:05 +03:00
2017-04-30 10:25:15 +03:00
typealias Pair = StateActionPair<UuidState<MainWindow.State>, OpenedFileList.Action>
typealias MainWindowPair = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
static let basePath = "/tools/markdown"
static let saveFirstPath = "/tools/markdown/save-first.html"
static let errorPath = "/tools/markdown/error.html"
static let nonePath = "/tools/markdown/empty.html"
2017-02-06 21:22:28 +03:00
2017-04-30 10:25:15 +03:00
func reduceOpenedFileList(_ pair: Pair) -> Pair {
var state = pair.state.payload
2017-01-22 16:22:05 +03:00
2017-04-30 10:25:15 +03:00
switch pair.action {
2017-01-22 16:22:05 +03:00
2017-04-30 10:25:15 +03:00
case let .open(buffer):
state.preview = PreviewUtils.state(for: pair.state.uuid, baseUrl: self.baseServerUrl, buffer: buffer)
2017-03-30 21:03:28 +03:00
}
2017-04-30 10:25:15 +03:00
return StateActionPair(state: UuidState(uuid: pair.state.uuid, state: state), action: pair.action)
}
2017-04-30 10:25:15 +03:00
func reduceMainWindow(_ pair: MainWindowPair) -> MainWindowPair {
var state = pair.state.payload
2017-04-30 10:25:15 +03:00
switch pair.action {
2017-04-30 10:25:15 +03:00
case let .setCurrentBuffer(buffer):
guard state.previewTool.isRefreshOnWrite else {
return pair
}
2017-04-30 10:25:15 +03:00
state.preview = PreviewUtils.state(for: pair.state.uuid, baseUrl: self.baseServerUrl, buffer: buffer)
state.preview.ignoreNextReverse = true
2017-04-30 10:25:15 +03:00
case .close:
state.preview = PreviewUtils.state(for: .none, baseUrl: self.baseServerUrl)
2017-04-30 10:25:15 +03:00
default:
return pair
2017-03-30 21:03:28 +03:00
}
2017-04-30 10:25:15 +03:00
return StateActionPair(state: UuidState(uuid: pair.state.uuid, state: state), action: pair.action)
}
2017-04-30 10:25:15 +03:00
init(baseServerUrl: URL) {
self.baseServerUrl = baseServerUrl
}
2017-04-30 10:25:15 +03:00
fileprivate let baseServerUrl: URL
2017-01-22 16:22:05 +03:00
}