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
|
|
|
|
2017-04-11 20:26:34 +03:00
|
|
|
static let basePath = "/tools/html-preview"
|
|
|
|
static let selectFirstPath = "/tools/html-preview/select-first.html"
|
2017-04-02 21:45:12 +03:00
|
|
|
|
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-04-02 21:45:12 +03:00
|
|
|
|
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
|
|
|
|
}
|