Skip to content

Commit

Permalink
Merge pull request #10 from loro-dev/fix-undo-onPush
Browse files Browse the repository at this point in the history
fix: undo onPush
  • Loading branch information
Leeeon233 authored Jan 6, 2025
2 parents 5c1637a + f8e49cc commit 0ca48e2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
46 changes: 37 additions & 9 deletions Sources/Loro/LoroFFI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ public protocol LoroDocProtocol : AnyObject {
*
* The data can be in arbitrary order. The import result will be the same.
*/
func importBatch(bytes: [Data]) throws
func importBatch(bytes: [Data]) throws -> ImportStatus

func importJsonUpdates(json: String) throws -> ImportStatus

Expand Down Expand Up @@ -3092,11 +3092,12 @@ open func `import`(bytes: Data)throws -> ImportStatus {
*
* The data can be in arbitrary order. The import result will be the same.
*/
open func importBatch(bytes: [Data])throws {try rustCallWithError(FfiConverterTypeLoroError.lift) {
open func importBatch(bytes: [Data])throws -> ImportStatus {
return try FfiConverterTypeImportStatus.lift(try rustCallWithError(FfiConverterTypeLoroError.lift) {
uniffi_loro_fn_method_lorodoc_import_batch(self.uniffiClonePointer(),
FfiConverterSequenceData.lower(bytes),$0
)
}
})
}

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

public protocol OnPush : AnyObject {

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

}

Expand Down Expand Up @@ -6574,11 +6575,12 @@ open class OnPushImpl:



open func onPush(undoOrRedo: UndoOrRedo, span: CounterSpan) -> UndoItemMeta {
open func onPush(undoOrRedo: UndoOrRedo, span: CounterSpan, diffEvent: DiffEvent?) -> UndoItemMeta {
return try! FfiConverterTypeUndoItemMeta.lift(try! rustCall() {
uniffi_loro_fn_method_onpush_on_push(self.uniffiClonePointer(),
FfiConverterTypeUndoOrRedo.lower(undoOrRedo),
FfiConverterTypeCounterSpan.lower(span),$0
FfiConverterTypeCounterSpan.lower(span),
FfiConverterOptionTypeDiffEvent.lower(diffEvent),$0
)
})
}
Expand All @@ -6597,6 +6599,7 @@ fileprivate struct UniffiCallbackInterfaceOnPush {
uniffiHandle: UInt64,
undoOrRedo: RustBuffer,
span: RustBuffer,
diffEvent: RustBuffer,
uniffiOutReturn: UnsafeMutablePointer<RustBuffer>,
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
) in
Expand All @@ -6607,7 +6610,8 @@ fileprivate struct UniffiCallbackInterfaceOnPush {
}
return uniffiObj.onPush(
undoOrRedo: try FfiConverterTypeUndoOrRedo.lift(undoOrRedo),
span: try FfiConverterTypeCounterSpan.lift(span)
span: try FfiConverterTypeCounterSpan.lift(span),
diffEvent: try FfiConverterOptionTypeDiffEvent.lift(diffEvent)
)
}

Expand Down Expand Up @@ -12113,6 +12117,30 @@ fileprivate struct FfiConverterOptionTypeCounterSpan: FfiConverterRustBuffer {
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterOptionTypeDiffEvent: FfiConverterRustBuffer {
typealias SwiftType = DiffEvent?

public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
guard let value = value else {
writeInt(&buf, Int8(0))
return
}
writeInt(&buf, Int8(1))
FfiConverterTypeDiffEvent.write(value, into: &buf)
}

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
switch try readInt(&buf) as Int8 {
case 0: return nil
case 1: return try FfiConverterTypeDiffEvent.read(from: &buf)
default: throw UniffiInternalError.unexpectedOptionalTag
}
}
}

#if swift(>=5.8)
@_documentation(visibility: private)
#endif
Expand Down Expand Up @@ -13085,7 +13113,7 @@ private var initializationResult: InitializationResult = {
if (uniffi_loro_checksum_method_lorodoc_import() != 11528) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_loro_checksum_method_lorodoc_import_batch() != 60062) {
if (uniffi_loro_checksum_method_lorodoc_import_batch() != 34010) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_loro_checksum_method_lorodoc_import_json_updates() != 57379) {
Expand Down Expand Up @@ -13532,7 +13560,7 @@ private var initializationResult: InitializationResult = {
if (uniffi_loro_checksum_method_onpop_on_pop() != 39438) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_loro_checksum_method_onpush_on_push() != 4043) {
if (uniffi_loro_checksum_method_onpush_on_push() != 46111) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_loro_checksum_method_styleconfigmap_get() != 25442) {
Expand Down
31 changes: 16 additions & 15 deletions loro-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion loro-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/uniffi-bindgen.rs"

[dependencies]
# loro-ffi = { path = "../../loro/crates/loro-ffi" }
loro-ffi = { git = "https://github.com/loro-dev/loro.git", tag = "[email protected]" }
loro-ffi = { git = "https://github.com/loro-dev/loro.git", branch = "main" }
uniffi = { version = "0.28.3" }

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion loro-rs/src/loro.udl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface Unsubscriber{

[Trait, WithForeign]
interface OnPush{
UndoItemMeta on_push(UndoOrRedo undo_or_redo, CounterSpan span);
UndoItemMeta on_push(UndoOrRedo undo_or_redo, CounterSpan span, DiffEvent? diff_event);
};

[Trait, WithForeign]
Expand Down

0 comments on commit 0ca48e2

Please sign in to comment.