wip: performance looks good, needs more testing

This commit is contained in:
Jonathan Kelley committed 2021-09-22 04:11:27 -04:00
1 parent 84b5ddded5
commit 4b6ca05f2c
9 files changed
+56 -42

No files matched your search

+4 -4
View File
@@ -56,7 +56,7 @@ pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T>(
cx.use_hook(
move |_| UseStateInner {
current_val: initial_state_fn(),
callback: cx.schedule_update(),
update_callback: cx.schedule_update(),
wip: Rc::new(RefCell::new(None)),
update_scheuled: Cell::new(false),
},
@@ -75,7 +75,7 @@ pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T>(
struct UseStateInner<T: 'static> {
current_val: T,
update_scheuled: Cell<bool>,
callback: Rc<dyn Fn()>,
update_callback: Rc<dyn Fn()>,
wip: Rc<RefCell<Option<T>>>,
}
@@ -98,13 +98,13 @@ impl<'a, T: 'static> UseState<'a, T> {
pub fn needs_update(&self) {
if !self.inner.update_scheuled.get() {
self.inner.update_scheuled.set(true);
(self.inner.callback)();
(self.inner.update_callback)();
}
}
pub fn set(&self, new_val: T) {
self.needs_update();
*self.inner.wip.borrow_mut() = Some(new_val);
self.needs_update();
}
pub fn get(&self) -> &'a T {