Swiftpack.co - Package - rxpipe/UndoProxy

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, wddwyss@gmail.com

License

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

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0