mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-01 10:02:36 +03:00
40 lines
897 B
Swift
40 lines
897 B
Swift
/**
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
* See LICENSE
|
|
*/
|
|
|
|
import Foundation
|
|
import RxSwift
|
|
|
|
class UiRootTransformer: Transformer {
|
|
|
|
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
return source.map { pair in
|
|
var appState = pair.state
|
|
let uuid = pair.action.uuid
|
|
|
|
switch pair.action.payload {
|
|
|
|
case .becomeKey:
|
|
appState.currentMainWindowUuid = uuid
|
|
appState.mainWindowTemplate = appState.mainWindows[uuid] ?? appState.mainWindowTemplate
|
|
|
|
case .close:
|
|
if appState.currentMainWindowUuid == uuid {
|
|
appState.currentMainWindowUuid = nil
|
|
}
|
|
|
|
appState.mainWindows.removeValue(forKey: uuid)
|
|
|
|
default:
|
|
return pair
|
|
|
|
}
|
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
|
}
|
|
}
|
|
}
|