1
1
mirror of https://github.com/qvacua/vimr.git synced 2025-01-01 18:23:48 +03:00
vimr/VimR/AppDelegateTransformer.swift

44 lines
1.1 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
import RxSwift
class AppDelegateTransformer: Transformer {
2017-01-22 16:22:05 +03:00
typealias Pair = StateActionPair<AppState, AppDelegate.Action>
2017-02-06 20:57:50 +03:00
init(baseServerUrl: URL) {
self.baseServerUrl = baseServerUrl
}
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
var state = pair.state
switch pair.action {
case let .newMainWindow(urls, cwd):
2017-01-22 16:22:05 +03:00
var mainWindow = state.currentMainWindow
mainWindow.uuid = UUID().uuidString
mainWindow.urlsToOpen = urls.toDict { url in MainWindow.OpenMode.default }
mainWindow.cwd = cwd
2017-02-06 21:22:28 +03:00
mainWindow.preview.server = self.baseServerUrl.appendingPathComponent(PreviewTransformer.nonePath)
2017-01-22 16:22:05 +03:00
state.mainWindows[mainWindow.uuid] = mainWindow
case .quitWithoutSaving, .quit:
state.mainWindows.removeAll()
state.quitWhenNoMainWindow = true
}
return StateActionPair(state: state, action: pair.action)
}
}
2017-02-06 20:57:50 +03:00
fileprivate let baseServerUrl: URL
}