1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 01:32:04 +03:00
vimr/VimR/States.swift

160 lines
3.0 KiB
Swift
Raw Normal View History

2017-01-22 16:22:05 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
import RxSwift
typealias ActionEmitter = Emitter<Any>
class Emitter<T> {
let observable: Observable<T>
init() {
self.observable = self.subject.asObservable().observeOn(scheduler)
}
func emit(_ action: T) {
self.subject.onNext(action)
}
deinit {
self.subject.onCompleted()
}
fileprivate let scheduler = SerialDispatchQueueScheduler(qos: .userInitiated)
fileprivate let subject = PublishSubject<T>()
}
class StateActionPair<S, A> {
2017-01-22 16:22:05 +03:00
let modified: Bool
let state: S
let action: A
2017-01-22 16:22:05 +03:00
init(state: S, action: A, modified: Bool = true) {
self.modified = modified
self.state = state
self.action = action
}
}
class UuidAction<A>: CustomStringConvertible {
let uuid: String
let payload: A
var description: String {
return "UuidAction(uuid: \(uuid), payload: \(String(reflecting: payload)))"
}
init(uuid: String, action: A) {
self.uuid = uuid
self.payload = action
}
}
class UuidState<S>: CustomStringConvertible {
let uuid: String
let payload: S
var description: String {
2017-02-03 00:39:05 +03:00
return "UuidState(uuid: \(uuid), payload: \(String(reflecting: payload)))"
}
init(uuid: String, state: S) {
self.uuid = uuid
self.payload = state
}
}
2017-01-22 16:22:05 +03:00
protocol Morpher {
2017-01-22 16:22:05 +03:00
associatedtype In
associatedtype Out
2017-01-22 16:22:05 +03:00
func transform(_ source: Observable<In>) -> Observable<Out>
}
2017-01-22 16:22:05 +03:00
protocol Transformer: Morpher {
2017-01-22 16:22:05 +03:00
associatedtype Element
2017-01-22 16:22:05 +03:00
typealias In = Element
typealias Out = Element
2017-01-22 16:22:05 +03:00
func transform(_ source: Observable<Element>) -> Observable<Element>
}
2017-02-05 17:17:25 +03:00
protocol Service {
associatedtype Element
func apply(_: Element)
}
2017-01-22 16:22:05 +03:00
struct AppState {
2017-01-22 16:22:05 +03:00
static let `default` = AppState(mainWindow: MainWindow.State.default)
2017-01-22 16:22:05 +03:00
var currentMainWindow: MainWindow.State
var mainWindows: [String: MainWindow.State] = [:]
2017-01-22 16:22:05 +03:00
let baseServerUrl: URL
2017-01-22 16:22:05 +03:00
init(mainWindow: MainWindow.State) {
self.baseServerUrl = URL(string: "http://localhost:\(NetUtils.openPort())")!
self.currentMainWindow = mainWindow
}
}
2017-02-06 00:39:55 +03:00
struct PreviewState {
2017-02-03 00:39:05 +03:00
2017-02-06 00:39:55 +03:00
static let `default` = PreviewState(buffer: nil, html: nil, server: nil)
var buffer: URL?
var html: URL?
var server: URL?
2017-02-03 00:39:05 +03:00
}
extension MainWindow {
2017-01-22 16:22:05 +03:00
struct State {
static let `default` = State(isAllToolsVisible: true, isToolButtonsVisible: true)
var isAllToolsVisible = true
var isToolButtonsVisible = true
2017-01-22 16:22:05 +03:00
////// transient
2017-02-06 00:39:55 +03:00
var preview = PreviewState.default
var isClosed = false
2017-02-03 00:39:05 +03:00
2017-01-22 16:22:05 +03:00
// neovim
var uuid = UUID().uuidString
2017-01-22 16:22:05 +03:00
var currentBuffer: NeoVimBuffer?
var buffers = [NeoVimBuffer]()
var cwd = FileUtils.userHomeUrl
var isDirty = false
var font = NSFont.userFixedPitchFont(ofSize: 13)!
var linespacing: CGFloat = 1
var isUseLigatures = false
var isUseInteractiveZsh = false
// transient^2
var urlsToOpen = [URL: OpenMode]()
init(isAllToolsVisible: Bool, isToolButtonsVisible: Bool) {
self.isAllToolsVisible = isAllToolsVisible
self.isToolButtonsVisible = isToolButtonsVisible
}
}
}