Skip to content

Commit aab00f4

Browse files
authored
chore: return is local when observer (#443)
* chore: return local when observe * chore: lint
1 parent c8daa21 commit aab00f4

File tree

11 files changed

+1432
-84
lines changed

11 files changed

+1432
-84
lines changed

collab/build.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2121
println!("cargo:rerun-if-changed={}", proto_file);
2222
}
2323

24+
let out_dir = std::env::var("OUT_DIR")?;
2425
prost_build::Config::new()
25-
.out_dir("src/entity/proto/")
26+
.out_dir(out_dir)
2627
.compile_protos(&proto_files, &["proto/entity/"])?;
2728

28-
// Run rustfmt on the generated files.
29-
let files = std::fs::read_dir("src/entity/proto/")?
30-
.filter_map(Result::ok)
31-
.filter(|entry| {
32-
entry
33-
.path()
34-
.extension()
35-
.map(|ext| ext == "rs")
36-
.unwrap_or(false)
37-
})
38-
.map(|entry| entry.path().display().to_string());
39-
40-
for file in files {
41-
Command::new("rustfmt").arg(file).status()?;
42-
}
29+
// Optional: keep generated sources formatted when building locally.
30+
// Ignore errors to avoid failing builds when `rustfmt` isn't available.
31+
let _ = Command::new("rustfmt")
32+
.arg(format!("{}/collab.rs", std::env::var("OUT_DIR")?))
33+
.status();
4334
Ok(())
4435
}

collab/src/database/database.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,11 @@ impl DatabaseBody {
18571857
let views: MapRef = root.get_or_init(&mut txn, VIEWS); // { DATABASE: { FIELDS: {:}, VIEWS: {:} } }
18581858
let metas: MapRef = root.get_or_init(&mut txn, DATABASE_METAS); // { DATABASE: { FIELDS: {:}, VIEWS: {:}, METAS: {:} } }
18591859

1860-
let fields = FieldMap::new(fields, Some(context.notifier.field_change_tx.clone()));
1860+
let fields = FieldMap::new(
1861+
origin.clone(),
1862+
fields,
1863+
Some(context.notifier.field_change_tx.clone()),
1864+
);
18611865
let views = DatabaseViews::new(origin, views, Some(context.notifier.view_change_tx.clone()));
18621866
let block = Block::new(
18631867
database_id,
@@ -1938,7 +1942,11 @@ impl DatabaseBody {
19381942
let views: MapRef = root.get_with_txn(&txn, VIEWS)?; // { DATABASE: { FIELDS: {:}, VIEWS: {:} } }
19391943
let metas: MapRef = root.get_with_txn(&txn, DATABASE_METAS)?; // { DATABASE: { FIELDS: {:}, VIEWS: {:}, METAS: {:} } }
19401944

1941-
let fields = FieldMap::new(fields, notifier.as_ref().map(|n| n.field_change_tx.clone()));
1945+
let fields = FieldMap::new(
1946+
origin.clone(),
1947+
fields,
1948+
notifier.as_ref().map(|n| n.field_change_tx.clone()),
1949+
);
19421950
let views = DatabaseViews::new(
19431951
origin,
19441952
views,

collab/src/database/fields/field_map.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::core::origin::CollabOrigin;
12
use crate::preclude::{Map, MapExt, MapRef, ReadTxn, Subscription, TransactionMut};
23

34
use crate::database::database::timestamp;
@@ -15,8 +16,12 @@ pub struct FieldMap {
1516
}
1617

1718
impl FieldMap {
18-
pub fn new(mut container: MapRef, field_change_tx: Option<FieldChangeSender>) -> Self {
19-
let subscription = field_change_tx.map(|tx| subscribe_field_change(&mut container, tx));
19+
pub fn new(
20+
origin: CollabOrigin,
21+
mut container: MapRef,
22+
field_change_tx: Option<FieldChangeSender>,
23+
) -> Self {
24+
let subscription = field_change_tx.map(|tx| subscribe_field_change(origin, &mut container, tx));
2025
Self {
2126
container,
2227
subscription,

0 commit comments

Comments
 (0)