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 MainWindowTransformer: Transformer {
|
|
|
|
|
|
|
|
typealias Pair = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
|
|
|
|
|
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
|
|
|
var state = pair.state.payload
|
|
|
|
|
|
|
|
switch pair.action {
|
|
|
|
|
|
|
|
case let .cd(to: cwd):
|
|
|
|
if state.cwd != cwd {
|
|
|
|
state.cwd = cwd
|
|
|
|
}
|
|
|
|
|
|
|
|
case let .setBufferList(buffers):
|
|
|
|
buffers
|
|
|
|
.flatMap { $0.url }
|
|
|
|
.forEach { state.urlsToOpen.removeValue(forKey: $0) }
|
|
|
|
state.buffers = buffers
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
case let .setCurrentBuffer(buffer):
|
|
|
|
state.currentBuffer = buffer
|
|
|
|
|
2017-01-17 21:47:59 +03:00
|
|
|
default:
|
2017-01-22 16:22:05 +03:00
|
|
|
return pair
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|