wip: remove the scoped trait

This commit is contained in:
Jonathan Kelley committed 2021-07-07 15:07:46 -04:00
1 parent 36542b482f
commit cca7c5fc3a
4 files changed
+85 -159

No files matched your search

+11 -11
View File
@@ -36,8 +36,8 @@ use std::{
/// }
/// }
/// ```
pub fn use_state_classic<'a, 'c, T: 'static, F: FnOnce() -> T>(
cx: impl Scoped<'a>,
pub fn use_state_classic<'a, 'c, T: 'static, F: FnOnce() -> T, P>(
cx: Context<'a, P>,
initial_state_fn: F,
) -> (&'a T, &'a Rc<dyn Fn(T)>) {
struct UseState<T: 'static> {
@@ -158,8 +158,8 @@ impl<'a, T: 'static + Display> std::fmt::Display for UseState<T> {
/// }
/// }
/// ```
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T>(
cx: impl Scoped<'a>,
pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T, P>(
cx: Context<'a, P>,
initial_state_fn: F,
) -> &'a UseState<T> {
cx.use_hook(
@@ -230,8 +230,8 @@ pub fn use_state<'a, 'c, T: 'static, F: FnOnce() -> T>(
/// To change it, use modify.
/// Modifications to this value do not cause updates to the component
/// Attach to inner context reference, so context can be consumed
pub fn use_ref<'a, T: 'static>(
cx: impl Scoped<'a>,
pub fn use_ref<'a, T: 'static, P>(
cx: Context<'a, P>,
initial_state_fn: impl FnOnce() -> T + 'static,
) -> &'a RefCell<T> {
cx.use_hook(|| RefCell::new(initial_state_fn()), |state| &*state, |_| {})
@@ -249,8 +249,8 @@ struct UseReducer<T: 'static, R: 'static> {
///
/// This is behaves almost exactly the same way as React's "use_state".
///
pub fn use_reducer<'a, 'c, State: 'static, Action: 'static>(
cx: impl Scoped<'a>,
pub fn use_reducer<'a, 'c, State: 'static, Action: 'static, P>(
cx: Context<'a, P>,
initial_state_fn: impl FnOnce() -> State,
_reducer: impl Fn(&mut State, Action),
) -> (&'a State, &'a Box<dyn Fn(Action)>) {
@@ -291,8 +291,8 @@ pub fn use_reducer<'a, 'c, State: 'static, Action: 'static>(
/// Use model makes it easy to use "models" as state for components. To modify the model, call "modify" and a clone of the
/// current model will be made, with a RefMut lock on it. Dioxus will never run your components multithreaded, so you can
/// be relatively sure that this won't fail in practice
pub fn use_model<'a, T: ToOwned<Owned = T> + 'static>(
cx: impl Scoped<'a>,
pub fn use_model<'a, T: ToOwned<Owned = T> + 'static, P>(
cx: Context<'a, P>,
f: impl FnOnce() -> T,
) -> &'a UseModel<T> {
cx.use_hook(
@@ -381,7 +381,7 @@ mod tests {
// };
}
pub fn use_is_initialized<P>(cx: Context<P>) -> bool {
pub fn use_is_initialized<'a, P>(cx: Context<'a, P>) -> bool {
let val = use_ref(cx, || false);
match *val.borrow() {
true => true,