wip: update hooks
This commit is contained in:
1 parent
96b3d56e09
commit
597a0456f5
6 files changed
+30
-21
No files matched your search
@@ -25,16 +25,16 @@ pub(crate) mod innerlude {
|
||||
}
|
||||
|
||||
pub use crate::innerlude::{
|
||||
Attribute, Component, Context, DioxusElement, DomEdit, Element, ElementId, EventHandler,
|
||||
EventPriority, IntoVNode, LazyNodes, Listener, Mutations, NodeFactory, Properties,
|
||||
SchedulerMsg, ScopeId, UserEvent, VElement, VFragment, VNode, VirtualDom,
|
||||
AnyContext, Attribute, Component, Context, DioxusElement, DomEdit, Element, ElementId,
|
||||
EventHandler, EventPriority, IntoVNode, LazyNodes, Listener, Mutations, NodeFactory,
|
||||
Properties, SchedulerMsg, Scope, ScopeId, UserEvent, VElement, VFragment, VNode, VirtualDom,
|
||||
};
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::component::{fc_to_builder, Fragment, Properties};
|
||||
pub use crate::innerlude::Context;
|
||||
pub use crate::innerlude::{
|
||||
Component, DioxusElement, Element, EventHandler, LazyNodes, NodeFactory, Scope,
|
||||
AnyContext, Component, DioxusElement, Element, EventHandler, LazyNodes, NodeFactory, Scope,
|
||||
};
|
||||
pub use crate::nodes::VNode;
|
||||
pub use crate::VirtualDom;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus_core::{prelude::Context, ScopeId};
|
||||
use dioxus_core::{prelude::Context, AnyContext, Scope, ScopeId};
|
||||
use std::{
|
||||
cell::{Cell, Ref, RefCell, RefMut},
|
||||
collections::HashSet,
|
||||
@@ -59,7 +59,8 @@ impl<T> ProvidedStateInner<T> {
|
||||
///
|
||||
///
|
||||
///
|
||||
pub fn use_shared_state<'a, T: 'static>(cx: Context<'a>) -> Option<UseSharedState<'a, T>> {
|
||||
pub fn use_shared_state<'a, T: 'static>(cx: &dyn AnyContext<'a>) -> Option<UseSharedState<'a, T>> {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
|_| {
|
||||
let scope_id = cx.scope_id();
|
||||
@@ -110,7 +111,7 @@ impl<T> Drop for SharedStateInner<T> {
|
||||
}
|
||||
|
||||
pub struct UseSharedState<'a, T: 'static> {
|
||||
pub(crate) cx: Context<'a>,
|
||||
pub(crate) cx: &'a Scope,
|
||||
pub(crate) value: &'a Rc<RefCell<T>>,
|
||||
pub(crate) root: &'a Rc<RefCell<ProvidedStateInner<T>>>,
|
||||
pub(crate) needs_notification: &'a Cell<bool>,
|
||||
@@ -175,7 +176,8 @@ where
|
||||
///
|
||||
///
|
||||
///
|
||||
pub fn use_provide_state<'a, T: 'static>(cx: Context<'a>, f: impl FnOnce() -> T) {
|
||||
pub fn use_provide_state<'a, T: 'static>(cx: &dyn AnyContext<'a>, f: impl FnOnce() -> T) {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
|_| {
|
||||
let state: ProvidedState<T> = RefCell::new(ProvidedStateInner {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus_core::Context;
|
||||
use dioxus_core::{AnyContext, Context, Scope};
|
||||
use futures::Future;
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
@@ -7,10 +7,10 @@ use std::{
|
||||
};
|
||||
|
||||
pub fn use_coroutine<'a, F: Future<Output = ()> + 'static>(
|
||||
cx: Context<'a>,
|
||||
cx: &dyn AnyContext<'a>,
|
||||
mut f: impl FnMut() -> F + 'a,
|
||||
) -> CoroutineHandle {
|
||||
//
|
||||
) -> CoroutineHandle<'a> {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
move |_| State {
|
||||
running: Default::default(),
|
||||
@@ -56,7 +56,7 @@ struct State {
|
||||
}
|
||||
|
||||
pub struct CoroutineHandle<'a> {
|
||||
cx: Context<'a>,
|
||||
cx: &'a Scope,
|
||||
inner: &'a State,
|
||||
}
|
||||
impl Clone for CoroutineHandle<'_> {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! In these cases, we provide `use_model` - a convenient way of abstracting over some state and async functions.
|
||||
|
||||
use dioxus_core::prelude::Context;
|
||||
use dioxus_core::prelude::{AnyContext, Context};
|
||||
use futures::Future;
|
||||
use std::{
|
||||
cell::{Cell, Ref, RefCell, RefMut},
|
||||
@@ -13,7 +13,11 @@ use std::{
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
pub fn use_model<T: 'static>(cx: Context, f: impl FnOnce() -> T) -> UseModel<T> {
|
||||
pub fn use_model<'a, T: 'static>(
|
||||
cx: &dyn AnyContext<'a>,
|
||||
f: impl FnOnce() -> T,
|
||||
) -> UseModel<'a, T> {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
|_| UseModelInner {
|
||||
update_scheduled: Cell::new(false),
|
||||
@@ -76,11 +80,12 @@ impl<'a, T: 'static> UseModel<'a, T> {
|
||||
}
|
||||
|
||||
// keep a coroutine going
|
||||
pub fn use_model_coroutine<T, F: Future<Output = ()> + 'static>(
|
||||
cx: Context,
|
||||
pub fn use_model_coroutine<'a, T, F: Future<Output = ()> + 'static>(
|
||||
cx: &dyn AnyContext<'a>,
|
||||
model: UseModel<T>,
|
||||
f: impl FnOnce(AppModels) -> F,
|
||||
) -> UseModelCoroutine {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
|_| {
|
||||
//
|
||||
|
||||
@@ -3,9 +3,10 @@ use std::{
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use dioxus_core::Context;
|
||||
use dioxus_core::AnyContext;
|
||||
|
||||
pub fn use_ref<T: 'static>(cx: Context, f: impl FnOnce() -> T) -> UseRef<T> {
|
||||
pub fn use_ref<'a, T: 'static>(cx: &dyn AnyContext<'a>, f: impl FnOnce() -> T) -> UseRef<'a, T> {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
|_| UseRefInner {
|
||||
update_scheduled: Cell::new(false),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus_core::prelude::Context;
|
||||
use dioxus_core::prelude::*;
|
||||
use std::{
|
||||
cell::{Cell, Ref, RefCell, RefMut},
|
||||
fmt::{Debug, Display},
|
||||
@@ -50,9 +50,10 @@ use std::{
|
||||
/// }
|
||||
/// ```
|
||||
pub fn use_state<'a, T: 'static>(
|
||||
cx: Context<'a>,
|
||||
cx: &dyn AnyContext<'a>,
|
||||
initial_state_fn: impl FnOnce() -> T,
|
||||
) -> UseState<'a, T> {
|
||||
let cx = cx.get_scope();
|
||||
cx.use_hook(
|
||||
move |_| {
|
||||
let first_val = initial_state_fn();
|
||||
|
||||
Reference in new issue
Block a user