Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ywasm: YDoc.transact #437

Open
Horusiath opened this issue May 11, 2024 · 0 comments
Open

ywasm: YDoc.transact #437

Horusiath opened this issue May 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Horusiath
Copy link
Collaborator

Horusiath commented May 11, 2024

The idea here is to bring ywasm compatibility with yjs further by providing native doc.transact(callback, origin) instead of current doc.beginTransaction.

This would also let us have more fined control over current ambient transaction context: we essentially could cache current transaction inside of the YDoc, just like yjs does, and reuse it on nested ydoc.transact calls.

// ywasm
#[wasm_bindgen]
pub struct YDoc {
  doc: yrs::Doc,
  current_txn: Option<YTransaction>
}

#[wasm_bindgen]
impl YDoc {
  #[wasm_bindgen]
  pub fn transact(&mut self, callback: js_sys::Function, origin: JsValue) {
    let mut txn = self.current_txn.get_or_insert_with(|| self.doc.transact_mut_with(origin).into());
    callback.call(&self.into())
  }
  
  #[wasm_bindgen(getter)]
  pub fn transaction(&mut self) -> Option<&YTransaction> {
    self.current_txn.as_mut()
  }
}
@Horusiath Horusiath added the enhancement New feature or request label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant