mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-27 15:53:31 +03:00
GH-405 Store prefs directly after changing
This commit is contained in:
parent
80d7c02571
commit
380c3ac61f
@ -22,6 +22,7 @@ class Context {
|
||||
let openQuicklyReducer = OpenQuicklyReducer()
|
||||
let previewReducer = PreviewReducer(baseServerUrl: baseServerUrl)
|
||||
|
||||
let prefService = PrefService()
|
||||
let previewService = PreviewService()
|
||||
|
||||
// For clean quit
|
||||
@ -45,7 +46,7 @@ class Context {
|
||||
.reduce(by: UiRootReducer())
|
||||
.reduce(by: openQuicklyReducer.forMainWindow)
|
||||
.filter { $0.modified }
|
||||
.apply(to: PrefService())
|
||||
.apply(to: prefService.forMainWindow)
|
||||
.map { $0.state },
|
||||
actionSource
|
||||
.mapOmittingNil { $0 as? FileMonitor.Action }
|
||||
@ -130,6 +131,7 @@ class Context {
|
||||
.map { $0.state }
|
||||
)
|
||||
.merge()
|
||||
.apply(to: prefService.forPrefPanes)
|
||||
.subscribe(onNext: self.emitAppState)
|
||||
.addDisposableTo(self.disposeBag)
|
||||
|
||||
@ -213,4 +215,8 @@ extension Observable {
|
||||
fileprivate func apply<S:Service>(to service: S) -> Observable<Element> where S.Pair == Element {
|
||||
return self.do(onNext: service.apply)
|
||||
}
|
||||
|
||||
fileprivate func apply<S:StateService>(to service: S) -> Observable<Element> where S.StateType == Element {
|
||||
return self.do(onNext: service.apply)
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,38 @@ import RxSwift
|
||||
|
||||
fileprivate let defaults = UserDefaults.standard
|
||||
|
||||
class PrefService: Service {
|
||||
|
||||
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
||||
class PrefService {
|
||||
|
||||
static let compatibleVersion = "168"
|
||||
static let lastCompatibleVersion = "128"
|
||||
|
||||
func apply(_ pair: Pair) {
|
||||
guard case .close = pair.action.payload else {
|
||||
return
|
||||
}
|
||||
|
||||
NSLog("Saving pref!")
|
||||
defaults.setValue(pair.state.dict(), forKey: PrefService.compatibleVersion)
|
||||
}
|
||||
let forMainWindow = PrefMainWindowService()
|
||||
let forPrefPanes = PrefPaneService()
|
||||
}
|
||||
|
||||
extension PrefService {
|
||||
|
||||
class PrefMainWindowService: Service {
|
||||
|
||||
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
||||
|
||||
func apply(_ pair: Pair) {
|
||||
guard case .close = pair.action.payload else {
|
||||
return
|
||||
}
|
||||
|
||||
NSLog("Saving pref!")
|
||||
defaults.setValue(pair.state.dict(), forKey: PrefService.compatibleVersion)
|
||||
}
|
||||
}
|
||||
|
||||
class PrefPaneService: StateService {
|
||||
|
||||
typealias StateType = AppState
|
||||
|
||||
func apply(_ state: StateType) {
|
||||
NSLog("Saving pref!")
|
||||
defaults.setValue(state.dict(), forKey: PrefService.compatibleVersion)
|
||||
}
|
||||
}
|
||||
}
|
@ -108,6 +108,13 @@ protocol Service {
|
||||
func apply(_: Pair)
|
||||
}
|
||||
|
||||
protocol StateService {
|
||||
|
||||
associatedtype StateType
|
||||
|
||||
func apply(_: StateType)
|
||||
}
|
||||
|
||||
protocol UiComponent {
|
||||
|
||||
associatedtype StateType
|
||||
|
Loading…
Reference in New Issue
Block a user