1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 02:54:31 +03:00
vimr/VimR/OpenQuicklyReducer.swift

87 lines
2.0 KiB
Swift
Raw Normal View History

2017-02-19 20:00:41 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
import RxSwift
2017-03-29 21:10:11 +03:00
class OpenQuicklyReducer {
2017-02-19 20:00:41 +03:00
2017-03-29 21:10:11 +03:00
let forMainWindow = MainWindowReducer()
let forOpenQuicklyWindow = OpenQuicklyWindowReducer()
2017-02-28 12:20:25 +03:00
}
2017-03-29 21:10:11 +03:00
extension OpenQuicklyReducer {
2017-02-19 20:00:41 +03:00
2017-03-29 21:10:11 +03:00
class OpenQuicklyWindowReducer: Reducer {
2017-02-19 20:00:41 +03:00
2017-02-28 12:20:25 +03:00
typealias Pair = StateActionPair<AppState, OpenQuicklyWindow.Action>
2017-02-19 20:00:41 +03:00
2017-02-28 12:20:25 +03:00
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
var appState = pair.state
2017-02-28 12:20:25 +03:00
appState.openQuickly.open = false
appState.openQuickly.flatFileItems = Observable.empty()
appState.openQuickly.cwd = FileUtils.userHomeUrl
2017-02-28 12:20:25 +03:00
switch pair.action {
2017-02-28 12:20:25 +03:00
case let .open(url):
guard let uuid = appState.currentMainWindowUuid else {
return pair
}
2017-02-28 12:20:25 +03:00
appState.mainWindows[uuid]?.urlsToOpen.append(Marked([url: .newTab]))
2017-02-19 20:00:41 +03:00
2017-02-28 12:20:25 +03:00
case .close:
break
}
2017-02-19 20:00:41 +03:00
2017-02-28 12:20:25 +03:00
return StateActionPair(state: appState, action: pair.action)
2017-02-19 20:00:41 +03:00
}
}
}
2017-03-29 21:10:11 +03:00
class MainWindowReducer: Reducer {
2017-02-28 12:20:25 +03:00
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
2017-02-28 12:20:25 +03:00
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
2017-02-23 00:51:24 +03:00
2017-02-28 12:20:25 +03:00
switch pair.action.payload {
2017-02-23 00:51:24 +03:00
2017-02-28 12:20:25 +03:00
case .openQuickly:
var appState = pair.state
2017-02-28 12:20:25 +03:00
guard let uuid = appState.currentMainWindowUuid else {
return pair
}
2017-02-28 12:20:25 +03:00
guard let cwd = appState.mainWindows[uuid]?.cwd else {
return pair
}
2017-02-23 00:51:24 +03:00
2017-02-28 12:20:25 +03:00
appState.openQuickly.open = true
appState.openQuickly.cwd = cwd
appState.openQuickly.flatFileItems = FileItemUtils.flatFileItems(
ofUrl: cwd,
ignorePatterns: appState.openQuickly.ignorePatterns,
ignoreToken: appState.openQuickly.ignoreToken,
root: appState.root
)
2017-02-28 12:20:25 +03:00
return StateActionPair(state: appState, action: pair.action)
2017-02-23 00:51:24 +03:00
2017-02-28 12:20:25 +03:00
default:
return pair
}
}
}
}
}