mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
Make use_future take an impl FnMut + 'static, don't include router prelude when we don't need to
This commit is contained in:
parent
cbdd8108e6
commit
6818bbe10a
22 changed files with 12 additions and 25 deletions
|
@ -7,7 +7,7 @@ fn main() {
|
|||
fn app() -> Element {
|
||||
let mut count = use_signal(|| 0);
|
||||
|
||||
use_future(|| async move {
|
||||
use_future(move || async move {
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||
count += 1;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Tiny CRM: A port of the Yew CRM example to Dioxus.
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
LaunchBuilder::new()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(|| {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch_desktop(App);
|
||||
|
|
|
@ -14,8 +14,6 @@ pub(crate) mod views;
|
|||
use oidc::{AuthRequestState, AuthTokenState};
|
||||
use router::Route;
|
||||
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
use crate::{
|
||||
constants::{DIOXUS_FRONT_AUTH_REQUEST, DIOXUS_FRONT_AUTH_TOKEN},
|
||||
oidc::ClientState,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::views::{header::AuthHeader, home::Home, login::Login, not_found::NotFound};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
pub enum Route {
|
||||
|
|
|
@ -127,7 +127,7 @@ pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
|
|||
|
||||
#[component]
|
||||
pub fn LoadClient() -> Element {
|
||||
let init_client_future = use_future(|| async move { init_oidc_client().await });
|
||||
let init_client_future = use_future(move || async move { init_oidc_client().await });
|
||||
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
|
||||
cx.render(match init_client_future.value() {
|
||||
Some(client_props) => match client_props {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
//!
|
||||
//! Run `dx serve` and navigate to `http://localhost:8080/blog?name=John&surname=Doe`
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch_desktop(|| {
|
||||
|
|
|
@ -29,7 +29,7 @@ fn app() -> Element {
|
|||
}
|
||||
|
||||
// use_future will spawn an infinitely running future that can be started and stopped
|
||||
use_future(|| async move {
|
||||
use_future(move || async move {
|
||||
loop {
|
||||
if running() {
|
||||
count += 1;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
#[derive(Routable, Clone, PartialEq)]
|
||||
enum Route {
|
||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
fn app() -> Element {
|
||||
let mut count = use_signal(|| 10);
|
||||
|
||||
use_future(|| async move {
|
||||
use_future(move || async move {
|
||||
let mut stream = some_stream();
|
||||
|
||||
while let Some(second) = stream.next().await {
|
||||
|
|
|
@ -50,7 +50,7 @@ fn app() -> Element {
|
|||
/// Suspense is achieved my moving the future into only the component that
|
||||
/// actually renders the data.
|
||||
fn Doggo() -> Element {
|
||||
let fut = use_future(|| async move {
|
||||
let fut = use_future(move || async move {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct DogApi {
|
||||
message: String,
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
fn app() -> Element {
|
||||
let mut state = use_signal(|| 0);
|
||||
|
||||
use_future(|| async move {
|
||||
use_future(move || async move {
|
||||
loop {
|
||||
state += 1;
|
||||
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
//! ```
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let config = LaunchBuilder::fullstack();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#![allow(unused)]
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
use dioxus_fullstack::{launch, prelude::*};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#![allow(missing_docs)]
|
||||
use crate::{use_hook_did_run, use_signal};
|
||||
use crate::{use_callback, use_hook_did_run, use_signal};
|
||||
use dioxus_core::{
|
||||
prelude::{spawn, use_drop, use_hook},
|
||||
Task,
|
||||
|
@ -11,15 +11,16 @@ use std::future::Future;
|
|||
/// A hook that allows you to spawn a future
|
||||
///
|
||||
/// Does not regenerate the future when dependencies change.
|
||||
pub fn use_future<F>(mut future: impl FnMut() -> F) -> UseFuture
|
||||
pub fn use_future<F>(future: impl FnMut() -> F + 'static) -> UseFuture
|
||||
where
|
||||
F: Future + 'static,
|
||||
{
|
||||
let mut callback = use_callback(future);
|
||||
let mut state = use_signal(|| UseFutureState::Pending);
|
||||
|
||||
// Create the task inside a copyvalue so we can reset it in-place later
|
||||
let task = use_hook(|| {
|
||||
let fut = future();
|
||||
let fut = callback.call();
|
||||
CopyValue::new(spawn(async move {
|
||||
fut.await;
|
||||
state.set(UseFutureState::Complete);
|
||||
|
|
|
@ -169,7 +169,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
fn app() -> Element {
|
||||
let mut count = use_signal(|| 0);
|
||||
|
||||
use_future(|| async move {
|
||||
use_future(move || async move {
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
count += 1;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[cfg(feature = "liveview")]
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus::router::prelude::*;
|
||||
|
||||
use dioxus_ssr::incremental::{DefaultRenderer, IncrementalRendererConfig};
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
use std::str::FromStr;
|
||||
|
||||
fn prepare<R: Routable>() -> String
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
fn app() -> Element {
|
||||
let mut signal = use_signal(|| 0);
|
||||
|
||||
use_future(|| async move {
|
||||
use_future(move || async move {
|
||||
loop {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
signal += 1;
|
||||
|
|
Loading…
Reference in a new issue