Make UseFuture Clone, factor out dependencies field (#1666)

This commit is contained in:
Exotik850 2023-11-27 15:42:48 -06:00 committed by GitHub
parent d9220d4e42
commit 18fa1e4831
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,13 +31,14 @@ where
let state = cx.use_hook(move || UseFuture {
update: cx.schedule_update(),
needs_regen: Cell::new(true),
needs_regen: Rc::new(Cell::new(true)),
state: val.clone(),
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
if let Some(task) = state.task.take() {
cx.remove_future(task);
@ -69,11 +70,11 @@ pub enum FutureState<'a, T> {
Regenerating(&'a T), // the old value
}
#[derive(Clone)]
pub struct UseFuture<T: 'static> {
update: Arc<dyn Fn()>,
needs_regen: Cell<bool>,
needs_regen: Rc<Cell<bool>>,
task: Rc<Cell<Option<TaskId>>>,
dependencies: Vec<Box<dyn Any>>,
state: UseState<Option<T>>,
}