mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
Make UseFuture Clone, factor out dependencies field
This commit is contained in:
parent
41182503ac
commit
9ca09e595d
1 changed files with 6 additions and 5 deletions
|
@ -31,13 +31,14 @@ where
|
||||||
|
|
||||||
let state = cx.use_hook(move || UseFuture {
|
let state = cx.use_hook(move || UseFuture {
|
||||||
update: cx.schedule_update(),
|
update: cx.schedule_update(),
|
||||||
needs_regen: Cell::new(true),
|
needs_regen: Rc::new(Cell::new(true)),
|
||||||
state: val.clone(),
|
state: val.clone(),
|
||||||
task: Default::default(),
|
task: Default::default(),
|
||||||
dependencies: Vec::new(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if dependencies.clone().apply(&mut state.dependencies) || state.needs_regen.get() {
|
let state_dependencies = cx.use_hook(Vec::new);
|
||||||
|
|
||||||
|
if dependencies.clone().apply(state_dependencies) || state.needs_regen.get() {
|
||||||
// kill the old one, if it exists
|
// kill the old one, if it exists
|
||||||
if let Some(task) = state.task.take() {
|
if let Some(task) = state.task.take() {
|
||||||
cx.remove_future(task);
|
cx.remove_future(task);
|
||||||
|
@ -69,11 +70,11 @@ pub enum FutureState<'a, T> {
|
||||||
Regenerating(&'a T), // the old value
|
Regenerating(&'a T), // the old value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct UseFuture<T: 'static> {
|
pub struct UseFuture<T: 'static> {
|
||||||
update: Arc<dyn Fn()>,
|
update: Arc<dyn Fn()>,
|
||||||
needs_regen: Cell<bool>,
|
needs_regen: Rc<Cell<bool>>,
|
||||||
task: Rc<Cell<Option<TaskId>>>,
|
task: Rc<Cell<Option<TaskId>>>,
|
||||||
dependencies: Vec<Box<dyn Any>>,
|
|
||||||
state: UseState<Option<T>>,
|
state: UseState<Option<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue