1
1
mirror of https://github.com/qvacua/vimr.git synced 2025-01-07 06:33:19 +03:00
vimr/VimR/UiRootTransformer.swift

35 lines
739 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 UiRootTransformer: Transformer {
2017-01-22 16:22:05 +03:00
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
2017-01-22 16:22:05 +03:00
var appState = pair.state
let uuid = pair.action.uuid
switch pair.action.payload {
case .becomeKey:
2017-01-22 16:22:05 +03:00
appState.currentMainWindow = appState.mainWindows[uuid] ?? appState.currentMainWindow
case .close:
2017-01-22 16:22:05 +03:00
appState.mainWindows.removeValue(forKey: uuid)
default:
2017-01-22 16:22:05 +03:00
return pair
}
2017-01-22 16:22:05 +03:00
return StateActionPair(state: appState, action: pair.action)
}
}
}