Skip to content

Commit 55e2496

Browse files
authored
Merge pull request #3 from loro-dev/dev
feat: update to v1.1.3
2 parents 865bcb7 + 99278ec commit 55e2496

15 files changed

+8562
-3641
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ if ProcessInfo.processInfo.environment["LOCAL_BUILD"] != nil {
1111
}else {
1212
FFIbinaryTarget = .binaryTarget(
1313
name: "LoroFFI",
14-
url: "https://github.com/loro-dev/loro-swift/releases/download/0.16.2-alpha.3/loroFFI.xcframework.zip",
15-
checksum: "9475660c4fcee609a498212b8ca038278b34c1325b30fece0ce5740d4025377a"
14+
url: "https://github.com/loro-dev/loro-swift/releases/download/1.0.0-alpha.5/loroFFI.xcframework.zip",
15+
checksum: "2b9c11aecf4f90ead28e12c8487b072e3fc406885e91ab2d1999b8c83040bd6c"
1616
)
1717
}
1818

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you have any suggestions for API, please feel free to create an issue or join
2323
- [x] Checkout
2424
- [x] Subscribe Event
2525
- [x] UndoManager
26-
- [ ] Bindings for all types in Loro
26+
- [x] Bindings for all types in Loro
2727
- [ ] Tests
2828
- [ ] Benchmarks
2929

@@ -37,7 +37,7 @@ let package = Package(
3737
products: [......],
3838
dependencies:[
3939
...,
40-
.package(url: "https://github.com/loro-dev/loro-swift.git", from: "0.16.2-alpha.3")
40+
.package(url: "https://github.com/loro-dev/loro-swift.git", from: "1.0.0-alpha.5")
4141
],
4242
targets:[
4343
.executableTarget(
@@ -66,20 +66,18 @@ let s = text.toString()
6666
// XCTAssertEqual(s, "bc")
6767

6868
// subscribe the event
69-
let subId = doc.subscribeRoot{ diffEvent in
69+
let sub = doc.subscribeRoot{ diffEvent in
7070
print(diffEvent)
7171
}
72-
// unsubscribe
73-
doc.unsubscribe(subId: id)
7472

7573
// export updates or snapshot
7674
let doc2 = LoroDoc()
7775
let snapshot = doc.exportSnapshot()
7876
let updates = doc.exportFrom(vv: VersionVector())
7977

8078
// import updates or snapshot
81-
try! doc2.import(snapshot)
82-
try! doc2.import(updates)
79+
let status = try! doc2.import(snapshot)
80+
let status2 = try! doc2.import(updates)
8381
// import batch of updates or snapshot
8482
try! doc2.importBatch(bytes: [snapshot, updates])
8583

Sources/Loro/Event.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
import Foundation
22

33
class ClosureSubscriber: Subscriber {
44
private let closure: (DiffEvent) -> Void
@@ -12,13 +12,25 @@ class ClosureSubscriber: Subscriber {
1212
}
1313
}
1414

15+
class ClosureLocalUpdate: LocalUpdateCallback{
16+
private let closure: (Data) -> Void
17+
18+
public init(closure: @escaping (Data) -> Void) {
19+
self.closure = closure
20+
}
21+
22+
public func onLocalUpdate(update: Data) {
23+
closure(update)
24+
}
25+
}
26+
1527
extension LoroDoc{
1628
/** Subscribe all the events.
1729
*
18-
* The callback will be invoked when any part of the [loro_internal::DocState] is changed.
30+
* The callback will be invoked when any part of the [DocState] is changed.
1931
* Returns a subscription id that can be used to unsubscribe.
2032
*/
21-
public func subscribeRoot(callback: @escaping (DiffEvent)->Void) -> SubId {
33+
public func subscribeRoot(callback: @escaping (DiffEvent)->Void) -> Subscription {
2234
let closureSubscriber = ClosureSubscriber(closure: callback)
2335
return self.subscribeRoot(subscriber: closureSubscriber)
2436
}
@@ -27,9 +39,23 @@ extension LoroDoc{
2739
*
2840
* The callback will be invoked when the container is changed.
2941
* Returns a subscription id that can be used to unsubscribe.
42+
*
43+
* The events will be emitted after a transaction is committed. A transaction is committed when:
44+
* - `doc.commit()` is called.
45+
* - `doc.exportFrom(version)` is called.
46+
* - `doc.import(data)` is called.
47+
* - `doc.checkout(version)` is called.
3048
*/
31-
public func subscribe(containerId: ContainerId, callback: @escaping (DiffEvent)->Void) -> SubId {
49+
public func subscribe(containerId: ContainerId, callback: @escaping (DiffEvent)->Void) -> Subscription {
3250
let closureSubscriber = ClosureSubscriber(closure: callback)
3351
return self.subscribe(containerId: containerId, subscriber: closureSubscriber)
3452
}
53+
54+
/**
55+
* Subscribe the local update of the document.
56+
*/
57+
public func subscribeLocalUpdate(callback: @escaping (Data)->Void)->Subscription{
58+
let closureLocalUpdate = ClosureLocalUpdate(closure: callback)
59+
return self.subscribeLocalUpdate(callback: closureLocalUpdate)
60+
}
3561
}

Sources/Loro/Loro.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,23 @@ extension UndoManager{
5353
}
5454
}
5555
}
56+
57+
58+
class ChangeAncestorsTravel: ChangeAncestorsTraveler{
59+
private let closure: (ChangeMeta)->Bool
60+
61+
public init(closure: @escaping (ChangeMeta)->Bool) {
62+
self.closure = closure
63+
}
64+
65+
func travel(change: ChangeMeta) -> Bool {
66+
closure(change)
67+
}
68+
}
69+
70+
extension LoroDoc{
71+
public func travelChangeAncestors(ids: [Id], f: @escaping (ChangeMeta)->Bool) throws {
72+
let closureSubscriber = ChangeAncestorsTravel(closure: f)
73+
try self.travelChangeAncestors(ids: ids, f: closureSubscriber)
74+
}
75+
}

0 commit comments

Comments
 (0)