wip: staticify?
This commit is contained in:
1 parent
78d093a945
commit
5ad81885e4
21 files changed
+433
-346
No files matched your search
@@ -10,7 +10,11 @@ pub use use_state_def::use_state;
|
||||
|
||||
mod use_state_def {
|
||||
use crate::innerlude::*;
|
||||
use std::{cell::RefCell, ops::DerefMut, rc::Rc};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
ops::{Deref, DerefMut},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
struct UseState<T: 'static> {
|
||||
new_val: Rc<RefCell<Option<T>>>,
|
||||
@@ -18,6 +22,22 @@ mod use_state_def {
|
||||
caller: Box<dyn Fn(T) + 'static>,
|
||||
}
|
||||
|
||||
struct UseStateHandle<'a, T> {
|
||||
inner: &'a T,
|
||||
}
|
||||
impl<'a, T> UseStateHandle<'a, T> {
|
||||
fn set(&self, new_val: T) {}
|
||||
fn modify(&self, f: impl FnOnce(&mut T)) {}
|
||||
}
|
||||
|
||||
impl<'a, T> Deref for UseStateHandle<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.inner
|
||||
}
|
||||
}
|
||||
|
||||
/// Store state between component renders!
|
||||
/// When called, this hook retrives a stored value and provides a setter to update that value.
|
||||
/// When the setter is called, the component is re-ran with the new value.
|
||||
@@ -175,9 +195,9 @@ mod use_reducer_def {
|
||||
|
||||
// #[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
|
||||
enum Actions {
|
||||
Incr,
|
||||
Decr,
|
||||
|
||||
Reference in new issue
Block a user