UndoProxy 0.2.0

UndoProxy 0.2.0

Maintained by Carl.



 
Depends on:
RxSwift~> 5.0
RxCocoa~> 5.0
 

UndoProxy 0.2.0

UndoProxy

Version License Platform

Manaul

import UndoProxy

enum Action: Undoable {
    case add(_ num: Int)
    case minus(_ num: Int)

    var opposite: Action {
        switch self {
        case .add(let val): return .minus(val)
        case .minus(let val): return .add(val)
        }
    }
}

class Calculator {
    var undoProxy = UndoProxy<Action>()
    var value: Int
    let disposeBag = DisposeBag()

    init(value: Int) {
        self.value = value
        undoProxy.signal
            .subscribe(onNext: { (action) in
                switch action {
                case .add(let val):
                    self.value += val
                case .minus(let val):
                    self.value -= val
                }
            })
            .disposed(by: disposeBag)
    }

    func API() {
      undoProxy.register(.add(1))
      undoProxy.dispatch(.add(1))
      undoProxy.dispatch([.add(1), .add(2)])
      undoProxy.canUndo
      undoProxy.canRedo
      undoProxy.undo()
      undoProxy.redo()
    }
}

Installation

Cocoapods

pod 'UndoProxy', '~> 0.1'

Swift Package Manager

.package(url: "https://github.com/rxpipe/UndoProxy.git")

Author

duan, [email protected]

License

RxTheme is available under the MIT license. See the LICENSE file for more info.