2017-01-22 16:22:05 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
|
|
|
class AppDelegateTransformer: Transformer {
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
typealias Pair = StateActionPair<AppState, AppDelegate.Action>
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
|
|
|
switch pair.action {
|
|
|
|
|
|
|
|
case let .newMainWindow(urls, cwd):
|
|
|
|
var state = pair.state
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
var mainWindow = state.currentMainWindow
|
2017-01-17 21:47:59 +03:00
|
|
|
mainWindow.uuid = UUID().uuidString
|
2017-01-22 16:22:05 +03:00
|
|
|
mainWindow.serverBaseUrl = state.baseServerUrl.appendingPathComponent("\(mainWindow.uuid)")
|
2017-01-17 21:47:59 +03:00
|
|
|
mainWindow.urlsToOpen = urls.toDict { url in MainWindow.OpenMode.default }
|
|
|
|
mainWindow.cwd = cwd
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
state.mainWindows[mainWindow.uuid] = mainWindow
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
return StateActionPair(state: state, action: pair.action)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|