mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-11 07:22:23 +03:00
39 lines
926 B
Swift
39 lines
926 B
Swift
/**
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
* See LICENSE
|
|
*/
|
|
|
|
import Foundation
|
|
import RxSwift
|
|
|
|
class FileMonitorReducer: Reducer {
|
|
|
|
typealias Pair = StateActionPair<AppState, FileMonitor.Action>
|
|
|
|
func reduce(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
return source.map { pair in
|
|
var state = pair.state
|
|
|
|
switch pair.action {
|
|
|
|
case let .change(in: url):
|
|
guard let fileItem = FileItemUtils.item(for: url, root: state.root, create: false) else {
|
|
return pair
|
|
}
|
|
|
|
fileItem.needsScanChildren = true
|
|
|
|
state.mainWindows
|
|
.filter { (uuid, mainWindow) in url == mainWindow.cwd || url.isContained(in: mainWindow.cwd) }
|
|
.map { $0.0 }
|
|
.forEach { uuid in
|
|
state.mainWindows[uuid]?.lastFileSystemUpdate = Marked(fileItem)
|
|
}
|
|
|
|
}
|
|
|
|
return StateActionPair(state: state, action: pair.action)
|
|
}
|
|
}
|
|
}
|