1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 03:25:03 +03:00

Remove unnec' properties

This commit is contained in:
Tae Won Ha 2017-02-28 10:20:25 +01:00
parent abc652d62f
commit 02ebe1e3c2
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 70 additions and 75 deletions

View File

@ -14,29 +14,29 @@ class StateContext {
init(_ initialState: AppState) {
let baseServerUrl = URL(string: "http://localhost:\(NetUtils.openPort())")!
self.httpServerService = HttpServerService(port: baseServerUrl.port ?? 0)
self.appDelegateTransformer = AppDelegateTransformer(baseServerUrl: baseServerUrl)
self.previewTransformer = PreviewTransformer(baseServerUrl: baseServerUrl)
self.previewToolTransformer = PreviewToolTransformer(baseServerUrl: baseServerUrl)
self.appState = initialState
self.stateSource = self.stateSubject.asObservable()
let actionSource = self.actionEmitter.observable
let openQuicklyTransformer = OpenQuicklyTransformer()
let previewTransformer = PreviewTransformer(baseServerUrl: baseServerUrl)
let previewService = PreviewService()
Observable
.of(
actionSource
.mapOmittingNil { $0 as? AppDelegate.Action }
.map { StateActionPair(state: self.appState, action: $0, modified: false) }
.transform(by: self.appDelegateTransformer)
.transform(by: AppDelegateTransformer(baseServerUrl: baseServerUrl))
.filter { $0.modified }
.map { $0.state },
actionSource
.mapOmittingNil { $0 as? UuidAction<MainWindow.Action> }
.map { StateActionPair(state: self.appState, action: $0, modified: false) }
.transform(by: UiRootTransformer())
.transform(by: MainWindowToOpenQuicklyTransformer())
.transform(by: openQuicklyTransformer.forMainWindow)
.filter { $0.modified }
.map { $0.state },
actionSource
@ -48,7 +48,7 @@ class StateContext {
actionSource
.mapOmittingNil { $0 as? OpenQuicklyWindow.Action }
.map { StateActionPair(state: self.appState, action: $0, modified: false) }
.transform(by: OpenQuicklyTransformer())
.transform(by: openQuicklyTransformer.forOpenQuicklyWindow)
.filter { $0.modified }
.map { $0.state }
)
@ -72,11 +72,11 @@ class StateContext {
action: action.payload,
modified: false)
}
.transform(by: self.mainWindowTransformer)
.transform(by: self.previewTransformer.forMainWindow)
.transform(by: MainWindowTransformer())
.transform(by: previewTransformer.forMainWindow)
.filter { $0.modified }
.apply(to: self.previewService.forMainWindow)
.apply(to: self.httpServerService)
.apply(to: previewService.forMainWindow)
.apply(to: HttpServerService(port: baseServerUrl.port ?? 0))
.map { $0.state },
actionSource
.mapOmittingNil { $0 as? UuidAction<PreviewTool.Action> }
@ -89,7 +89,7 @@ class StateContext {
action: action.payload,
modified: false)
}
.transform(by: self.previewToolTransformer)
.transform(by: PreviewToolTransformer(baseServerUrl: baseServerUrl))
.filter { $0.modified }
.map { $0.state },
actionSource
@ -103,7 +103,7 @@ class StateContext {
action: action.payload,
modified: false)
}
.transform(by: self.fileBrowserTransformer)
.transform(by: FileBrowserTransformer())
.filter { $0.modified }
.map { $0.state },
actionSource
@ -117,10 +117,10 @@ class StateContext {
action: action.payload,
modified: false)
}
.transform(by: self.openedFileListTransformer)
.transform(by: self.previewTransformer.forOpenedFileList)
.transform(by: OpenedFileListTransformer())
.transform(by: previewTransformer.forOpenedFileList)
.filter { $0.modified }
.apply(to: self.previewService.forOpenedFileList)
.apply(to: previewService.forOpenedFileList)
.map { $0.state }
)
.merge()
@ -173,20 +173,6 @@ class StateContext {
fileprivate let disposeBag = DisposeBag()
fileprivate var appState: AppState
fileprivate let appDelegateTransformer: AppDelegateTransformer
fileprivate let mainWindowTransformer = MainWindowTransformer()
fileprivate let previewTransformer: PreviewTransformer
fileprivate let previewToolTransformer: PreviewToolTransformer
fileprivate let fileBrowserTransformer = FileBrowserTransformer()
fileprivate let openedFileListTransformer = OpenedFileListTransformer()
fileprivate let previewService = PreviewService()
fileprivate let httpServerService: HttpServerService
}
extension Observable {

View File

@ -6,72 +6,81 @@
import Foundation
import RxSwift
class MainWindowToOpenQuicklyTransformer: Transformer {
class OpenQuicklyTransformer {
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
let forMainWindow = MainWindowTransformer()
let forOpenQuicklyWindow = OpenQuicklyWindowTransformer()
}
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
extension OpenQuicklyTransformer {
switch pair.action.payload {
class OpenQuicklyWindowTransformer: Transformer {
case .openQuickly:
typealias Pair = StateActionPair<AppState, OpenQuicklyWindow.Action>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
var appState = pair.state
guard let uuid = appState.currentMainWindowUuid else {
return pair
}
appState.openQuickly.open = false
appState.openQuickly.flatFileItems = Observable.empty()
appState.openQuickly.cwd = FileUtils.userHomeUrl
guard let cwd = appState.mainWindows[uuid]?.cwd else {
return pair
}
switch pair.action {
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
)
case let .open(url):
guard let uuid = appState.currentMainWindowUuid else {
return pair
}
appState.mainWindows[uuid]?.urlsToOpen.append(Marked([url: .newTab]))
case .close:
break
}
return StateActionPair(state: appState, action: pair.action)
default:
return pair
}
}
}
}
class OpenQuicklyTransformer: Transformer {
class MainWindowTransformer: Transformer {
typealias Pair = StateActionPair<AppState, OpenQuicklyWindow.Action>
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
var appState = pair.state
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
appState.openQuickly.open = false
appState.openQuickly.flatFileItems = Observable.empty()
appState.openQuickly.cwd = FileUtils.userHomeUrl
switch pair.action.payload {
switch pair.action {
case .openQuickly:
var appState = pair.state
case let .open(url):
guard let uuid = appState.currentMainWindowUuid else {
guard let uuid = appState.currentMainWindowUuid else {
return pair
}
guard let cwd = appState.mainWindows[uuid]?.cwd else {
return pair
}
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
)
return StateActionPair(state: appState, action: pair.action)
default:
return pair
}
appState.mainWindows[uuid]?.urlsToOpen.append(Marked([url: .newTab]))
case .close:
break
}
return StateActionPair(state: appState, action: pair.action)
}
}
}