wip: update hooks
This commit is contained in:
1 parent
96b3d56e09
commit
597a0456f5
6 files changed
+30
-21
No files matched your search
@@ -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(
|
||||
|_| {
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user