1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-11 07:22:23 +03:00
vimr/VimR/FileMonitorReducer.swift

34 lines
788 B
Swift
Raw Normal View History

2017-02-19 20:00:41 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
2017-04-30 10:25:15 +03:00
class FileMonitorReducer {
2017-02-19 20:00:41 +03:00
typealias Pair = StateActionPair<AppState, FileMonitor.Action>
2017-04-30 10:25:15 +03:00
func reduce(_ pair: Pair) -> Pair {
var state = pair.state
2017-02-19 22:15:10 +03:00
2017-04-30 10:25:15 +03:00
switch pair.action {
2017-02-19 20:00:41 +03:00
2017-04-30 10:25:15 +03:00
case let .change(in: url):
2017-05-14 13:06:21 +03:00
if let fileItem = FileItemUtils.item(for: url, root: state.openQuickly.root, create: false) {
fileItem.needsScanChildren = true
2017-04-30 10:25:15 +03:00
}
2017-04-30 10:25:15 +03:00
state.mainWindows
.filter { (uuid, mainWindow) in url == mainWindow.cwd || url.isContained(in: mainWindow.cwd) }
.map { $0.0 }
.forEach { uuid in
2017-05-14 13:06:21 +03:00
state.mainWindows[uuid]?.lastFileSystemUpdate = Marked(url)
2017-04-30 10:25:15 +03:00
}
2017-02-19 22:15:10 +03:00
2017-02-19 20:00:41 +03:00
}
2017-04-30 10:25:15 +03:00
return StateActionPair(state: state, action: pair.action)
2017-02-19 20:00:41 +03:00
}
}