fix: should be readonly when doc is in detached mode

This commit is contained in:
Zixuan Chen 2023-08-04 14:45:22 +08:00
parent db4eb64d42
commit 640828bf26
2 changed files with 10 additions and 0 deletions

View file

@ -120,6 +120,12 @@ impl LoroDoc {
/// The origin will be propagated to the events.
/// There can only be one active transaction at a time for a [LoroDoc].
pub fn txn_with_origin(&self, origin: &str) -> Result<Transaction, LoroError> {
if self.is_detached() {
return Err(LoroError::TransactionError(
String::from("LoroDoc is in detached mode. OpLog and AppState are using different version. So it's readonly.").into_boxed_str(),
));
}
let mut txn =
Transaction::new_with_origin(self.state.clone(), self.oplog.clone(), origin.into());
if self.state.lock().unwrap().is_recording() {

View file

@ -138,6 +138,10 @@ impl DocState {
self.event_recorder.recording_diff
}
pub fn refresh_peer_id(&mut self) {
self.peer = DefaultRandom.next_u64();
}
/// Take all the diffs that are recorded and convert them to events.
pub fn take_events(&mut self) -> Vec<DocDiff> {
if !self.is_recording() {