Open
Description
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()
}
}