automerge / automerge-swift-archived

Wrapper around Swift types that can be modified concurrently by different users, and merged again automatically (a CRDT).
MIT License
159 stars 14 forks source link

#4 Add += and -= operators on Counter API #52

Closed kkostov closed 2 years ago

kkostov commented 2 years ago

As proposed in #4, Extends the Counter API to enable increment and decrement of the counter's value using addition assignment and subtraction assignment operators e.g.

struct Schema: Codable, Equatable {
    var counter: Counter?
}

var doc1 = Document(Schema())
let _ = doc1.change {
    $0.counter?.set(3)
}

let _ = doc1.change {
    $0.counter -= 1
    XCTAssertEqual($0.counter?.get(), 2)
}

let _ = doc1.change {
    $0.counter += 1
    XCTAssertEqual($0.counter?.get(), 3)
}
kkostov commented 2 years ago

Awesome! I don't actually have permission to merge it by myself 😇