mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
feat: add Resource::map
This commit is contained in:
parent
b932bd5e04
commit
3b88c8ccd2
1 changed files with 14 additions and 0 deletions
|
@ -129,6 +129,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn map<U>(&self, f: impl FnOnce(&T) -> U) -> Option<U>
|
||||
where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
self.data.try_with(|n| n.as_ref().map(f))?
|
||||
}
|
||||
|
||||
/// Re-runs the async function with the current source data.
|
||||
pub fn refetch(&self) {
|
||||
*self.refetch.write() += 1;
|
||||
|
@ -675,6 +683,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn map<U>(&self, f: impl FnOnce(&T) -> U) -> Option<U> {
|
||||
self.data
|
||||
.try_with(|n| n.as_ref().map(|n| Some(f(n))))?
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// Re-runs the async function with the current source data.
|
||||
pub fn refetch(&self) {
|
||||
self.refetch.try_update(|n| *n += 1);
|
||||
|
|
Loading…
Reference in a new issue