Skip to content

Commit 0ca48e2

Browse files
authored
Merge pull request #10 from loro-dev/fix-undo-onPush
fix: undo onPush
2 parents 5c1637a + f8e49cc commit 0ca48e2

File tree

4 files changed

+55
-26
lines changed

4 files changed

+55
-26
lines changed

Sources/Loro/LoroFFI.swift

+37-9
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ public protocol LoroDocProtocol : AnyObject {
23442344
*
23452345
* The data can be in arbitrary order. The import result will be the same.
23462346
*/
2347-
func importBatch(bytes: [Data]) throws
2347+
func importBatch(bytes: [Data]) throws -> ImportStatus
23482348

23492349
func importJsonUpdates(json: String) throws -> ImportStatus
23502350

@@ -3092,11 +3092,12 @@ open func `import`(bytes: Data)throws -> ImportStatus {
30923092
*
30933093
* The data can be in arbitrary order. The import result will be the same.
30943094
*/
3095-
open func importBatch(bytes: [Data])throws {try rustCallWithError(FfiConverterTypeLoroError.lift) {
3095+
open func importBatch(bytes: [Data])throws -> ImportStatus {
3096+
return try FfiConverterTypeImportStatus.lift(try rustCallWithError(FfiConverterTypeLoroError.lift) {
30963097
uniffi_loro_fn_method_lorodoc_import_batch(self.uniffiClonePointer(),
30973098
FfiConverterSequenceData.lower(bytes),$0
30983099
)
3099-
}
3100+
})
31003101
}
31013102

31023103
open func importJsonUpdates(json: String)throws -> ImportStatus {
@@ -6520,7 +6521,7 @@ public func FfiConverterTypeOnPop_lower(_ value: OnPop) -> UnsafeMutableRawPoint
65206521

65216522
public protocol OnPush : AnyObject {
65226523

6523-
func onPush(undoOrRedo: UndoOrRedo, span: CounterSpan) -> UndoItemMeta
6524+
func onPush(undoOrRedo: UndoOrRedo, span: CounterSpan, diffEvent: DiffEvent?) -> UndoItemMeta
65246525

65256526
}
65266527

@@ -6574,11 +6575,12 @@ open class OnPushImpl:
65746575

65756576

65766577

6577-
open func onPush(undoOrRedo: UndoOrRedo, span: CounterSpan) -> UndoItemMeta {
6578+
open func onPush(undoOrRedo: UndoOrRedo, span: CounterSpan, diffEvent: DiffEvent?) -> UndoItemMeta {
65786579
return try! FfiConverterTypeUndoItemMeta.lift(try! rustCall() {
65796580
uniffi_loro_fn_method_onpush_on_push(self.uniffiClonePointer(),
65806581
FfiConverterTypeUndoOrRedo.lower(undoOrRedo),
6581-
FfiConverterTypeCounterSpan.lower(span),$0
6582+
FfiConverterTypeCounterSpan.lower(span),
6583+
FfiConverterOptionTypeDiffEvent.lower(diffEvent),$0
65826584
)
65836585
})
65846586
}
@@ -6597,6 +6599,7 @@ fileprivate struct UniffiCallbackInterfaceOnPush {
65976599
uniffiHandle: UInt64,
65986600
undoOrRedo: RustBuffer,
65996601
span: RustBuffer,
6602+
diffEvent: RustBuffer,
66006603
uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
66016604
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
66026605
) in
@@ -6607,7 +6610,8 @@ fileprivate struct UniffiCallbackInterfaceOnPush {
66076610
}
66086611
return uniffiObj.onPush(
66096612
undoOrRedo: try FfiConverterTypeUndoOrRedo.lift(undoOrRedo),
6610-
span: try FfiConverterTypeCounterSpan.lift(span)
6613+
span: try FfiConverterTypeCounterSpan.lift(span),
6614+
diffEvent: try FfiConverterOptionTypeDiffEvent.lift(diffEvent)
66116615
)
66126616
}
66136617

@@ -12113,6 +12117,30 @@ fileprivate struct FfiConverterOptionTypeCounterSpan: FfiConverterRustBuffer {
1211312117
}
1211412118
}
1211512119

12120+
#if swift(>=5.8)
12121+
@_documentation(visibility: private)
12122+
#endif
12123+
fileprivate struct FfiConverterOptionTypeDiffEvent: FfiConverterRustBuffer {
12124+
typealias SwiftType = DiffEvent?
12125+
12126+
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
12127+
guard let value = value else {
12128+
writeInt(&buf, Int8(0))
12129+
return
12130+
}
12131+
writeInt(&buf, Int8(1))
12132+
FfiConverterTypeDiffEvent.write(value, into: &buf)
12133+
}
12134+
12135+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
12136+
switch try readInt(&buf) as Int8 {
12137+
case 0: return nil
12138+
case 1: return try FfiConverterTypeDiffEvent.read(from: &buf)
12139+
default: throw UniffiInternalError.unexpectedOptionalTag
12140+
}
12141+
}
12142+
}
12143+
1211612144
#if swift(>=5.8)
1211712145
@_documentation(visibility: private)
1211812146
#endif
@@ -13085,7 +13113,7 @@ private var initializationResult: InitializationResult = {
1308513113
if (uniffi_loro_checksum_method_lorodoc_import() != 11528) {
1308613114
return InitializationResult.apiChecksumMismatch
1308713115
}
13088-
if (uniffi_loro_checksum_method_lorodoc_import_batch() != 60062) {
13116+
if (uniffi_loro_checksum_method_lorodoc_import_batch() != 34010) {
1308913117
return InitializationResult.apiChecksumMismatch
1309013118
}
1309113119
if (uniffi_loro_checksum_method_lorodoc_import_json_updates() != 57379) {
@@ -13532,7 +13560,7 @@ private var initializationResult: InitializationResult = {
1353213560
if (uniffi_loro_checksum_method_onpop_on_pop() != 39438) {
1353313561
return InitializationResult.apiChecksumMismatch
1353413562
}
13535-
if (uniffi_loro_checksum_method_onpush_on_push() != 4043) {
13563+
if (uniffi_loro_checksum_method_onpush_on_push() != 46111) {
1353613564
return InitializationResult.apiChecksumMismatch
1353713565
}
1353813566
if (uniffi_loro_checksum_method_styleconfigmap_get() != 25442) {

loro-rs/Cargo.lock

+16-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loro-rs/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ path = "src/uniffi-bindgen.rs"
1515

1616
[dependencies]
1717
# loro-ffi = { path = "../../loro/crates/loro-ffi" }
18-
loro-ffi = { git = "https://github.com/loro-dev/loro.git", tag = "loro-ffi@1.1.3" }
18+
loro-ffi = { git = "https://github.com/loro-dev/loro.git", branch = "main" }
1919
uniffi = { version = "0.28.3" }
2020

2121
[build-dependencies]

loro-rs/src/loro.udl

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface Unsubscriber{
4747

4848
[Trait, WithForeign]
4949
interface OnPush{
50-
UndoItemMeta on_push(UndoOrRedo undo_or_redo, CounterSpan span);
50+
UndoItemMeta on_push(UndoOrRedo undo_or_redo, CounterSpan span, DiffEvent? diff_event);
5151
};
5252

5353
[Trait, WithForeign]

0 commit comments

Comments
 (0)