feat: add fromCheckout to wasm

This commit is contained in:
Zixuan Chen 2023-11-08 16:22:21 +08:00
parent 08e4ed9d40
commit fdd24bd836
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

View file

@ -592,6 +592,7 @@ fn call_subscriber(ob: observer::Observer, e: DiffEvent) {
origin: e.doc.origin.to_string(),
target: e.container.id.clone(),
diff: e.container.diff.to_owned(),
from_checkout: e.doc.from_checkout,
}
// PERF: converting the events into js values may hurt performance
.into_js();
@ -609,6 +610,7 @@ fn call_after_micro_task(ob: observer::Observer, e: DiffEvent) {
let copy = drop_handler.clone();
let event = Event {
from_children: e.from_children,
from_checkout: e.doc.from_checkout,
local: e.doc.local,
origin: e.doc.origin.to_string(),
target: e.container.id.clone(),
@ -643,6 +645,7 @@ pub struct Event {
pub from_children: bool,
origin: String,
target: ContainerID,
from_checkout: bool,
diff: Diff,
path: JsValue,
}
@ -651,6 +654,7 @@ impl Event {
fn into_js(self) -> JsValue {
let obj = js_sys::Object::new();
Reflect::set(&obj, &"local".into(), &self.local.into()).unwrap();
Reflect::set(&obj, &"fromCheckout".into(), &self.from_checkout.into()).unwrap();
Reflect::set(&obj, &"fromChildren".into(), &self.from_children.into()).unwrap();
Reflect::set(&obj, &"origin".into(), &self.origin.into()).unwrap();
Reflect::set(&obj, &"target".into(), &self.target.to_string().into()).unwrap();

View file

@ -64,8 +64,19 @@ export type MapDiff = {
export type Diff = ListDiff | TextDiff | MapDiff;
export interface LoroEvent {
/**
* If true, this event was triggered by a local change.
*/
local: boolean;
origin?: string;
/**
* If true, this event was triggered by a child container.
*/
fromChildren: boolean;
/**
* If true, this event was triggered by a checkout.
*/
fromCheckout: boolean;
diff: Diff;
target: ContainerID;
path: Path;