diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index fa1a1d14..af65de36 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -597,6 +597,13 @@ impl Loro { /// /// You can specify the `origin` and `timestamp` of the commit. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// NOTE: Timestamps are forced to be in ascending order. /// If you commit a new change with a timestamp that is less than the existing one, /// the largest existing timestamp will be used instead. @@ -1060,6 +1067,13 @@ impl Loro { /// /// Returns a subscription ID, which can be used to unsubscribe. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// @example /// ```ts /// import { Loro } from "loro-crdt"; @@ -1770,6 +1784,13 @@ impl LoroText { /// Subscribe to the changes of the text. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// returns a subscription id, which can be used to unsubscribe. pub fn subscribe(&self, f: js_sys::Function) -> JsResult { let observer = observer::Observer::new(f); @@ -2115,7 +2136,14 @@ impl LoroMap { /// Subscribe to the changes of the map. /// - /// returns a subscription id, which can be used to unsubscribe. + /// Returns a subscription id, which can be used to unsubscribe. + /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. /// /// @param {Listener} f - Event listener /// @@ -2406,6 +2434,13 @@ impl LoroList { /// /// Returns a subscription id, which can be used to unsubscribe. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// @example /// ```ts /// import { Loro } from "loro-crdt"; @@ -2733,6 +2768,13 @@ impl LoroMovableList { /// /// Returns a subscription id, which can be used to unsubscribe. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// @example /// ```ts /// import { Loro } from "loro-crdt"; @@ -3386,6 +3428,13 @@ impl LoroTree { /// If a tree container is subscribed, the event of metadata changes will also be received as a MapDiff. /// And event's `path` will end with `TreeID`. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// @example /// ```ts /// import { Loro } from "loro-crdt"; diff --git a/crates/loro/src/lib.rs b/crates/loro/src/lib.rs index 4433195f..12326224 100644 --- a/crates/loro/src/lib.rs +++ b/crates/loro/src/lib.rs @@ -275,8 +275,13 @@ impl LoroDoc { /// Commit the cumulative auto commit transaction. /// /// There is a transaction behind every operation. - /// It will automatically commit when users invoke export or import. - /// The event will be sent after a transaction is committed + /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. pub fn commit(&self) { self.doc.commit_then_renew() } @@ -403,9 +408,16 @@ impl LoroDoc { /// Subscribe the events of a container. /// - /// The callback will be invoked when the container is changed. + /// The callback will be invoked after a transaction that change the container. /// Returns a subscription id that can be used to unsubscribe. /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. + /// /// # Example /// /// ``` @@ -449,6 +461,13 @@ impl LoroDoc { /// /// The callback will be invoked when any part of the [loro_internal::DocState] is changed. /// Returns a subscription id that can be used to unsubscribe. + /// + /// The events will be emitted after a transaction is committed. A transaction is committed when: + /// + /// - `doc.commit()` is called. + /// - `doc.exportFrom(version)` is called. + /// - `doc.import(data)` is called. + /// - `doc.checkout(version)` is called. pub fn subscribe_root(&self, callback: Subscriber) -> SubID { // self.doc.subscribe_root(callback) self.doc.subscribe_root(Arc::new(move |e| { @@ -456,7 +475,7 @@ impl LoroDoc { })) } - /// Remove a subscription. + /// Remove a subscription by subscription id. pub fn unsubscribe(&self, id: SubID) { self.doc.unsubscribe(id) }