Skip to content

Commit

Permalink
fix: panic at fewer places in stores (#3551)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdi739 authored Feb 7, 2025
1 parent cd64bb9 commit 706617a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions reactive_stores/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use reactive_graph::{
DefinedAt, IsDisposed, Notify, ReadUntracked, Track, UntrackableGuard,
Write,
},
unwrap_signal,
};
use std::{
fmt::Debug,
Expand Down Expand Up @@ -44,14 +43,14 @@ where
self.inner
.try_get_value()
.map(|inner| inner.get_trigger(path))
.unwrap_or_else(unwrap_signal!(self))
.unwrap_or_default()
}

fn path(&self) -> impl IntoIterator<Item = StorePathSegment> {
self.inner
.try_get_value()
.map(|inner| inner.path().into_iter().collect::<Vec<_>>())
.unwrap_or_else(unwrap_signal!(self))
.unwrap_or_default()
}

fn reader(&self) -> Option<Self::Reader> {
Expand Down
3 changes: 1 addition & 2 deletions reactive_stores/src/keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ where
|| self.inner.latest_keys(),
)
.flatten()
.map(|(_, idx)| idx)
.expect("reading from a keyed field that has not yet been created");
.map(|(_, idx)| idx)?;

Some(WriteGuard::new(
trigger.children,
Expand Down
7 changes: 3 additions & 4 deletions reactive_stores/src/store_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use reactive_graph::{
guards::{Plain, UntrackedWriteGuard, WriteGuard},
ArcTrigger,
},
traits::{DefinedAt, Track, UntrackableGuard},
unwrap_signal,
traits::{Track, UntrackableGuard},
};
use std::{iter, ops::Deref, sync::Arc};

Expand Down Expand Up @@ -105,15 +104,15 @@ where
self.inner
.try_get_value()
.map(|n| n.get_trigger(path))
.unwrap_or_else(unwrap_signal!(self))
.unwrap_or_default()
}

#[track_caller]
fn path(&self) -> impl IntoIterator<Item = StorePathSegment> {
self.inner
.try_get_value()
.map(|n| n.path().into_iter().collect::<Vec<_>>())
.unwrap_or_else(unwrap_signal!(self))
.unwrap_or_default()
}

#[track_caller]
Expand Down

0 comments on commit 706617a

Please sign in to comment.