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

34 lines
865 B
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>
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
mainWindow.uuid = UUID().uuidString
2017-01-22 16:22:05 +03:00
mainWindow.serverBaseUrl = state.baseServerUrl.appendingPathComponent("\(mainWindow.uuid)")
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
return StateActionPair(state: state, action: pair.action)
}
}
}
}