1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 00:34:26 +03:00

GH-383 Reload only when a new file gets selected

This commit is contained in:
Tae Won Ha 2017-04-02 21:55:24 +02:00
parent 55cddec9ad
commit 8902aafedd
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 18 additions and 5 deletions

View File

@ -39,6 +39,16 @@ class HtmlPreviewTool: NSView, UiComponent {
source
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [unowned self] state in
guard let serverUrl = state.htmlPreview.server else {
return
}
if serverUrl.mark == self.mark {
return
}
self.mark = serverUrl.mark
self.webview.load(URLRequest(url: serverUrl.payload))
})
.addDisposableTo(self.disposeBag)
}
@ -53,6 +63,8 @@ class HtmlPreviewTool: NSView, UiComponent {
fileprivate let emitter: ActionEmitter
fileprivate let uuid: String
fileprivate var mark = Token()
fileprivate let webview: WKWebView
fileprivate let disposeBag = DisposeBag()

View File

@ -25,8 +25,9 @@ class HtmlPreviewToolReducer: Reducer {
case let .selectHtmlFile(url):
state.htmlPreview.htmlFile = url
state.htmlPreview.server = self.baseServerUrl
.appendingPathComponent("\(uuid)/\(HtmlPreviewToolReducer.basePath)/index.html")
state.htmlPreview.server = Marked(
self.baseServerUrl .appendingPathComponent("\(uuid)/\(HtmlPreviewToolReducer.basePath)/index.html")
)
}

View File

@ -44,9 +44,9 @@ extension HttpServerService {
return
}
let basePath = serverUrl.deletingLastPathComponent().path
let basePath = serverUrl.payload.deletingLastPathComponent().path
self.server.GET[serverUrl.path] = shareFile(htmlFileUrl.path)
self.server.GET[serverUrl.payload.path] = shareFile(htmlFileUrl.path)
self.server["\(basePath)/:path"] = shareFilesFromDirectory(htmlFileUrl.parent.path)
}

View File

@ -140,7 +140,7 @@ struct HtmlPreviewState {
static let `default` = HtmlPreviewState()
var htmlFile: URL?
var server: URL?
var server: Marked<URL>?
}
struct AppearanceState: SerializableState {