mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-22 08:38:27 +00:00
rename flush_sync to wait_for_next_render
This commit is contained in:
parent
2e3a730ed5
commit
287416cfa7
7 changed files with 17 additions and 24 deletions
packages
core
hooks/src
signals/src
|
@ -250,14 +250,14 @@ pub fn after_render(f: impl FnMut() + 'static) {
|
|||
Runtime::with_current_scope(|cx| cx.push_after_render(f));
|
||||
}
|
||||
|
||||
/// Wait for the virtualdom to finish its sync work before proceeding
|
||||
/// Wait for the next render to complete
|
||||
///
|
||||
/// This is useful if you've just triggered an update and want to wait for it to finish before proceeding with valid
|
||||
/// DOM nodes.
|
||||
///
|
||||
/// Effects rely on this to ensure that they only run effects after the DOM has been updated. Without flush_sync effects
|
||||
/// Effects rely on this to ensure that they only run effects after the DOM has been updated. Without wait_for_next_render effects
|
||||
/// are run immediately before diffing the DOM, which causes all sorts of out-of-sync weirdness.
|
||||
pub async fn flush_sync() {
|
||||
pub async fn wait_for_next_render() {
|
||||
// Wait for the flush lock to be available
|
||||
// We release it immediately, so it's impossible for the lock to be held longer than this function
|
||||
Runtime::with(|rt| rt.render_signal.subscribe())
|
||||
|
|
|
@ -88,14 +88,14 @@ pub use crate::innerlude::{
|
|||
/// This includes types like [`Element`], and [`Component`].
|
||||
pub mod prelude {
|
||||
pub use crate::innerlude::{
|
||||
consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, flush_sync,
|
||||
generation, has_context, needs_update, needs_update_any, parent_scope, provide_context,
|
||||
consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, generation,
|
||||
has_context, needs_update, needs_update_any, parent_scope, provide_context,
|
||||
provide_root_context, remove_future, schedule_update, schedule_update_any, spawn,
|
||||
spawn_forever, suspend, try_consume_context, use_after_render, use_before_render, use_drop,
|
||||
use_error_boundary, use_hook, use_hook_with_cleanup, AnyValue, Attribute, Component,
|
||||
ComponentFunction, Element, ErrorBoundary, Event, EventHandler, Fragment, HasAttributes,
|
||||
IntoAttributeValue, IntoDynNode, OptionStringFromMarker, Properties, Runtime, RuntimeGuard,
|
||||
ScopeId, ScopeState, SuperFrom, SuperInto, Task, Template, TemplateAttribute, TemplateNode,
|
||||
Throw, VNode, VNodeInner, VirtualDom,
|
||||
use_error_boundary, use_hook, use_hook_with_cleanup, wait_for_next_render, AnyValue,
|
||||
Attribute, Component, ComponentFunction, Element, ErrorBoundary, Event, EventHandler,
|
||||
Fragment, HasAttributes, IntoAttributeValue, IntoDynNode, OptionStringFromMarker,
|
||||
Properties, Runtime, RuntimeGuard, ScopeId, ScopeState, SuperFrom, SuperInto, Task,
|
||||
Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, VirtualDom,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ async fn flushing() {
|
|||
spawn(async move {
|
||||
let mut channel = BROADCAST.with(|b| b.1.resubscribe());
|
||||
for _ in 0..10 {
|
||||
flush_sync().await;
|
||||
wait_for_next_render().await;
|
||||
println!("Task 1 recved");
|
||||
channel.recv().await.unwrap();
|
||||
println!("Task 1");
|
||||
|
@ -116,7 +116,7 @@ async fn flushing() {
|
|||
spawn(async move {
|
||||
let mut channel = BROADCAST.with(|b| b.1.resubscribe());
|
||||
for _ in 0..10 {
|
||||
flush_sync().await;
|
||||
wait_for_next_render().await;
|
||||
println!("Task 2 recved");
|
||||
channel.recv().await.unwrap();
|
||||
println!("Task 2");
|
||||
|
|
|
@ -35,7 +35,7 @@ pub fn use_effect(mut callback: impl FnMut() + 'static) {
|
|||
rc.changed().await;
|
||||
|
||||
// Wait for the dom the be finished with sync work
|
||||
flush_sync().await;
|
||||
wait_for_next_render().await;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
#![allow(missing_docs)]
|
||||
use crate::{use_callback, use_hook_did_run, use_signal, UseCallback};
|
||||
use dioxus_core::{
|
||||
prelude::{flush_sync, spawn, use_hook},
|
||||
Task,
|
||||
};
|
||||
use dioxus_core::{prelude::*, Task};
|
||||
use dioxus_signals::*;
|
||||
use dioxus_signals::{Readable, Writable};
|
||||
use std::future::Future;
|
||||
|
||||
/// A hook that allows you to spawn a future.
|
||||
/// This future will **not** run on the server
|
||||
/// The future is spawned on the next call to `flush_sync` which means that it will not run on the server.
|
||||
/// The future is spawned on the next call to `wait_for_next_render` which means that it will not run on the server.
|
||||
/// To run a future on the server, you should use `spawn` directly.
|
||||
/// `use_future` **won't return a value**.
|
||||
/// If you want to return a value from a future, use `use_resource` instead.
|
||||
|
@ -45,14 +42,13 @@ where
|
|||
let mut callback = use_callback(move || {
|
||||
let fut = future();
|
||||
spawn(async move {
|
||||
flush_sync().await;
|
||||
state.set(UseFutureState::Pending);
|
||||
fut.await;
|
||||
state.set(UseFutureState::Ready);
|
||||
})
|
||||
});
|
||||
|
||||
// Create the task inside a copyvalue so we can reset it in-place later
|
||||
// Create the task inside a CopyValue so we can reset it in-place later
|
||||
let task = use_hook(|| CopyValue::new(callback.call()));
|
||||
|
||||
// Early returns in dioxus have consequences for use_memo, use_resource, and use_future, etc
|
||||
|
|
|
@ -135,8 +135,6 @@ where
|
|||
|
||||
spawn(async move {
|
||||
loop {
|
||||
// Wait for the dom the be finished with sync work
|
||||
flush_sync().await;
|
||||
rc.changed().await;
|
||||
|
||||
let new = rc.run_in(|| f(dependencies_signal.read().clone()));
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
|||
ReadOnlySignal, ReadableRef,
|
||||
};
|
||||
use dioxus_core::{
|
||||
prelude::{flush_sync, spawn, IntoAttributeValue},
|
||||
prelude::{spawn, IntoAttributeValue},
|
||||
ScopeId,
|
||||
};
|
||||
use generational_box::{AnyStorage, Storage, SyncStorage, UnsyncStorage};
|
||||
|
@ -109,7 +109,6 @@ impl<T: PartialEq + 'static> Signal<T> {
|
|||
|
||||
spawn(async move {
|
||||
loop {
|
||||
flush_sync().await;
|
||||
rc.changed().await;
|
||||
let new = f();
|
||||
if new != *state.peek() {
|
||||
|
|
Loading…
Add table
Reference in a new issue