mirror of
https://github.com/loro-dev/loro.git
synced 2024-11-25 04:38:58 +00:00
fix: should be readonly when doc is in detached mode
This commit is contained in:
parent
db4eb64d42
commit
640828bf26
2 changed files with 10 additions and 0 deletions
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue