1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-27 14:14:19 +03:00
vimr/VimR/HtmlPreviewToolReducer.swift

38 lines
911 B
Swift
Raw Normal View History

2017-03-24 19:47:08 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
2017-04-30 10:25:15 +03:00
class HtmlPreviewToolReducer {
typealias Pair = StateActionPair<UuidState<MainWindow.State>, HtmlPreviewTool.Action>
2017-03-24 19:47:08 +03:00
static let basePath = "/tools/html-preview"
static let selectFirstPath = "/tools/html-preview/select-first.html"
2017-03-24 19:47:08 +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
let uuid = pair.state.uuid
2017-03-24 19:47:08 +03:00
2017-04-30 10:25:15 +03:00
switch pair.action {
2017-03-24 19:47:08 +03:00
2017-04-30 10:25:15 +03:00
case let .selectHtmlFile(url):
state.htmlPreview.htmlFile = url
state.htmlPreview.server = Marked(
self.baseServerUrl.appendingPathComponent("\(uuid)/\(HtmlPreviewToolReducer.basePath)/index.html")
)
2017-03-24 19:47:08 +03:00
}
2017-04-30 10:25:15 +03:00
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
2017-03-24 19:47:08 +03:00
}
fileprivate let baseServerUrl: URL
}