Struct ywasm::Transaction
source · pub struct Transaction { /* private fields */ }
Implementations§
source§impl YTransaction
impl YTransaction
pub fn from_implicit( txn: &ImplicitTransaction, ) -> Result<Option<Ref<'_, Self>>, JsValue>
pub fn from_implicit_mut( txn: &ImplicitTransaction, ) -> Result<Option<RefMut<'_, Self>>, JsValue>
pub fn try_ref_from_js_value(value: &JsValue) -> Result<Ref<'_, Self>, JsValue>
pub fn try_mut_from_js_value( value: &JsValue, ) -> Result<RefMut<'_, Self>, JsValue>
pub fn from_ref(txn: &TransactionMut<'_>) -> Self
pub fn as_ref(&self) -> &TransactionMut<'static>
pub fn as_mut(&mut self) -> Result<&mut TransactionMut<'static>, JsValue>
source§impl YTransaction
impl YTransaction
sourcepub fn before_state(&self) -> Map
pub fn before_state(&self) -> Map
Returns state vector describing the state of the document at the moment when the transaction began.
sourcepub fn after_state(&self) -> Map
pub fn after_state(&self) -> Map
Returns state vector describing the current state of the document.
pub fn pending_structs(&self) -> Result<JsValue, JsValue>
sourcepub fn pending_ds(&self) -> Option<Map>
pub fn pending_ds(&self) -> Option<Map>
Returns a unapplied delete set, that was received in one of the previous remote updates. This DeleteSet is waiting for a missing updates to arrive in order to be applied.
sourcepub fn delete_set(&self) -> Map
pub fn delete_set(&self) -> Map
Returns a delete set containing information about all blocks removed as part of a current transaction.
pub fn origin(&self) -> JsValue
sourcepub fn get(&self, id: JsValue) -> Result<JsValue, JsValue>
pub fn get(&self, id: JsValue) -> Result<JsValue, JsValue>
Given a logical identifier of the collection (obtained via YText.id
, YArray.id
etc.),
attempts to return an instance of that collection in the scope of current document.
Returns undefined
if an instance was not defined locally, haven’t been integrated or
has been deleted.
sourcepub fn commit(&mut self) -> Result<(), JsValue>
pub fn commit(&mut self) -> Result<(), JsValue>
Triggers a post-update series of operations without free
ing the transaction. This includes
compaction and optimization of internal representation of updates, triggering events etc.
ywasm transactions are auto-committed when they are free
d.
sourcepub fn state_vector_v1(&self) -> Uint8Array
pub fn state_vector_v1(&self) -> Uint8Array
Encodes a state vector of a given transaction document into its binary representation using
lib0 v1 encoding. State vector is a compact representation of updates performed on a given
document and can be used by encode_state_as_update
on remote peer to generate a delta
update payload to synchronize changes between peers.
Example:
import YDoc from 'ywasm'
/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()
// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()
try {
const localSV = localTxn.stateVectorV1()
const remoteDelta = remoteTxn.diffV1(localSv)
localTxn.applyV1(remoteDelta)
} finally {
localTxn.free()
remoteTxn.free()
}
sourcepub fn diff_v1(&self, vector: Option<Uint8Array>) -> Result<Uint8Array, JsValue>
pub fn diff_v1(&self, vector: Option<Uint8Array>) -> Result<Uint8Array, JsValue>
Encodes all updates that have happened since a given version vector
into a compact delta
representation using lib0 v1 encoding. If vector
parameter has not been provided, generated
delta payload will contain all changes of a current ywasm document, working effectively as
its state snapshot.
Example:
import YDoc from 'ywasm'
/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()
// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()
try {
const localSV = localTxn.stateVectorV1()
const remoteDelta = remoteTxn.diffV1(localSv)
localTxn.applyV1(remoteDelta)
} finally {
localTxn.free()
remoteTxn.free()
}
sourcepub fn diff_v2(&self, vector: Option<Uint8Array>) -> Result<Uint8Array, JsValue>
pub fn diff_v2(&self, vector: Option<Uint8Array>) -> Result<Uint8Array, JsValue>
Encodes all updates that have happened since a given version vector
into a compact delta
representation using lib0 v1 encoding. If vector
parameter has not been provided, generated
delta payload will contain all changes of a current ywasm document, working effectively as
its state snapshot.
Example:
import YDoc from 'ywasm'
/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()
// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()
try {
const localSV = localTxn.stateVectorV1()
const remoteDelta = remoteTxn.diffV2(localSv)
localTxn.applyV2(remoteDelta)
} finally {
localTxn.free()
remoteTxn.free()
}
sourcepub fn apply_v1(&mut self, diff: Uint8Array) -> Result<(), JsValue>
pub fn apply_v1(&mut self, diff: Uint8Array) -> Result<(), JsValue>
Applies delta update generated by the remote document replica to a current transaction’s document. This method assumes that a payload maintains lib0 v1 encoding format.
Example:
import YDoc from 'ywasm'
/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()
// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()
try {
const localSV = localTxn.stateVectorV1()
const remoteDelta = remoteTxn.diffV1(localSv)
localTxn.applyV1(remoteDelta)
} finally {
localTxn.free()
remoteTxn.free()
}
sourcepub fn apply_v2(&mut self, diff: Uint8Array) -> Result<(), JsValue>
pub fn apply_v2(&mut self, diff: Uint8Array) -> Result<(), JsValue>
Applies delta update generated by the remote document replica to a current transaction’s document. This method assumes that a payload maintains lib0 v2 encoding format.
Example:
import YDoc from 'ywasm'
/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()
// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()
try {
const localSV = localTxn.stateVectorV1()
const remoteDelta = remoteTxn.diffV2(localSv)
localTxn.applyV2(remoteDelta)
} finally {
localTxn.free()
remoteTxn.free()
}
pub fn encode_update(&self) -> Uint8Array
pub fn encode_update_v2(&self) -> Uint8Array
Methods from Deref<Target = TransactionMut<'static>>§
pub fn doc(&self) -> &Doc
pub fn events(&self) -> Option<&StoreEvents>
sourcepub fn before_state(&self) -> &StateVector
pub fn before_state(&self) -> &StateVector
Corresponding document’s state vector at the moment when current transaction was created.
sourcepub fn after_state(&self) -> &StateVector
pub fn after_state(&self) -> &StateVector
State vector of the transaction after [Transaction::commit] has been called.
sourcepub fn delete_set(&self) -> &DeleteSet
pub fn delete_set(&self) -> &DeleteSet
Data about deletions performed in the scope of current transaction.
sourcepub fn origin(&self) -> Option<&Origin>
pub fn origin(&self) -> Option<&Origin>
Returns origin of the transaction if any was defined. Read-write transactions can get an origin assigned via Transact::try_transact_mut_with/Transact::transact_mut_with methods.
sourcepub fn changed_parent_types(&self) -> &[BranchPtr]
pub fn changed_parent_types(&self) -> &[BranchPtr]
Returns a list of root level types changed in a scope of the current transaction. This list is not filled right away, but as a part of TransactionMut::commit process.
sourcepub fn encode_update_v1(&self) -> Vec<u8> ⓘ
pub fn encode_update_v1(&self) -> Vec<u8> ⓘ
Encodes changes made within the scope of the current transaction using lib0 v1 encoding.
Document updates are idempotent and commutative. Caveats:
- It doesn’t matter in which order document updates are applied.
- As long as all clients receive the same document updates, all clients end up with the same content.
- Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
sourcepub fn encode_update_v2(&self) -> Vec<u8> ⓘ
pub fn encode_update_v2(&self) -> Vec<u8> ⓘ
Encodes changes made within the scope of the current transaction using lib0 v2 encoding.
Document updates are idempotent and commutative. Caveats:
- It doesn’t matter in which order document updates are applied.
- As long as all clients receive the same document updates, all clients end up with the same content.
- Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
sourcepub fn encode_update<E>(&self, encoder: &mut E)where
E: Encoder,
pub fn encode_update<E>(&self, encoder: &mut E)where
E: Encoder,
Encodes changes made within the scope of the current transaction.
Document updates are idempotent and commutative. Caveats:
- It doesn’t matter in which order document updates are applied.
- As long as all clients receive the same document updates, all clients end up with the same content.
- Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
Trait Implementations§
source§impl Deref for YTransaction
impl Deref for YTransaction
source§impl<'doc> From<TransactionMut<'doc>> for YTransaction
impl<'doc> From<TransactionMut<'doc>> for YTransaction
source§fn from(value: TransactionMut<'doc>) -> Self
fn from(value: TransactionMut<'doc>) -> Self
source§impl From<YTransaction> for JsValue
impl From<YTransaction> for JsValue
source§fn from(value: YTransaction) -> Self
fn from(value: YTransaction) -> Self
source§impl FromWasmAbi for YTransaction
impl FromWasmAbi for YTransaction
source§impl IntoWasmAbi for YTransaction
impl IntoWasmAbi for YTransaction
source§impl LongRefFromWasmAbi for YTransaction
impl LongRefFromWasmAbi for YTransaction
source§impl OptionFromWasmAbi for YTransaction
impl OptionFromWasmAbi for YTransaction
source§impl OptionIntoWasmAbi for YTransaction
impl OptionIntoWasmAbi for YTransaction
source§impl RefFromWasmAbi for YTransaction
impl RefFromWasmAbi for YTransaction
§type Anchor = Ref<'static, YTransaction>
type Anchor = Ref<'static, YTransaction>
Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.source§impl RefMutFromWasmAbi for YTransaction
impl RefMutFromWasmAbi for YTransaction
source§impl TryFromJsValue for YTransaction
impl TryFromJsValue for YTransaction
source§impl VectorFromWasmAbi for YTransaction
impl VectorFromWasmAbi for YTransaction
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[YTransaction]>
source§impl VectorIntoWasmAbi for YTransaction
impl VectorIntoWasmAbi for YTransaction
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[YTransaction]>) -> Self::Abi
source§impl WasmDescribeVector for YTransaction
impl WasmDescribeVector for YTransaction
Auto Trait Implementations§
impl Freeze for YTransaction
impl !RefUnwindSafe for YTransaction
impl !Send for YTransaction
impl !Sync for YTransaction
impl Unpin for YTransaction
impl !UnwindSafe for YTransaction
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.