rename flush_sync to wait_for_next_render

This commit is contained in:
Evan Almloff committed 2024-03-04 19:52:17 -06:00
1 parent 2e3a730ed5
commit 287416cfa7
7 files changed
+17 -24

No files matched your search

+3 -3
View File
@@ -250,14 +250,14 @@ pub fn after_render(f: impl FnMut() + 'static) {
Runtime::with_current_scope(|cx| cx.push_after_render(f)); 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 /// This is useful if you've just triggered an update and want to wait for it to finish before proceeding with valid
/// DOM nodes. /// 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. /// 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 // 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 // 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()) Runtime::with(|rt| rt.render_signal.subscribe())
+7 -7
View File
@@ -88,14 +88,14 @@ pub use crate::innerlude::{
/// This includes types like [`Element`], and [`Component`]. /// This includes types like [`Element`], and [`Component`].
pub mod prelude { pub mod prelude {
pub use crate::innerlude::{ pub use crate::innerlude::{
consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, flush_sync, consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, generation,
generation, has_context, needs_update, needs_update_any, parent_scope, provide_context, has_context, needs_update, needs_update_any, parent_scope, provide_context,
provide_root_context, remove_future, schedule_update, schedule_update_any, spawn, 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, 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, use_error_boundary, use_hook, use_hook_with_cleanup, wait_for_next_render, AnyValue,
ComponentFunction, Element, ErrorBoundary, Event, EventHandler, Fragment, HasAttributes, Attribute, Component, ComponentFunction, Element, ErrorBoundary, Event, EventHandler,
IntoAttributeValue, IntoDynNode, OptionStringFromMarker, Properties, Runtime, RuntimeGuard, Fragment, HasAttributes, IntoAttributeValue, IntoDynNode, OptionStringFromMarker,
ScopeId, ScopeState, SuperFrom, SuperInto, Task, Template, TemplateAttribute, TemplateNode, Properties, Runtime, RuntimeGuard, ScopeId, ScopeState, SuperFrom, SuperInto, Task,
Throw, VNode, VNodeInner, VirtualDom, Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, VirtualDom,
}; };
} }
+2 -2
View File
@@ -103,7 +103,7 @@ async fn flushing() {
spawn(async move { spawn(async move {
let mut channel = BROADCAST.with(|b| b.1.resubscribe()); let mut channel = BROADCAST.with(|b| b.1.resubscribe());
for _ in 0..10 { for _ in 0..10 {
flush_sync().await; wait_for_next_render().await;
println!("Task 1 recved"); println!("Task 1 recved");
channel.recv().await.unwrap(); channel.recv().await.unwrap();
println!("Task 1"); println!("Task 1");
@@ -116,7 +116,7 @@ async fn flushing() {
spawn(async move { spawn(async move {
let mut channel = BROADCAST.with(|b| b.1.resubscribe()); let mut channel = BROADCAST.with(|b| b.1.resubscribe());
for _ in 0..10 { for _ in 0..10 {
flush_sync().await; wait_for_next_render().await;
println!("Task 2 recved"); println!("Task 2 recved");
channel.recv().await.unwrap(); channel.recv().await.unwrap();
println!("Task 2"); println!("Task 2");
+1 -1
View File
@@ -35,7 +35,7 @@ pub fn use_effect(mut callback: impl FnMut() + 'static) {
rc.changed().await; rc.changed().await;
// Wait for the dom the be finished with sync work // Wait for the dom the be finished with sync work
flush_sync().await; wait_for_next_render().await;
} }
}); });
}); });
+3 -7
View File
@@ -1,16 +1,13 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use crate::{use_callback, use_hook_did_run, use_signal, UseCallback}; use crate::{use_callback, use_hook_did_run, use_signal, UseCallback};
use dioxus_core::{ use dioxus_core::{prelude::*, Task};
prelude::{flush_sync, spawn, use_hook},
Task,
};
use dioxus_signals::*; use dioxus_signals::*;
use dioxus_signals::{Readable, Writable}; use dioxus_signals::{Readable, Writable};
use std::future::Future; use std::future::Future;
/// A hook that allows you to spawn a future. /// A hook that allows you to spawn a future.
/// This future will **not** run on the server /// 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. /// To run a future on the server, you should use `spawn` directly.
/// `use_future` **won't return a value**. /// `use_future` **won't return a value**.
/// If you want to return a value from a future, use `use_resource` instead. /// 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 mut callback = use_callback(move || {
let fut = future(); let fut = future();
spawn(async move { spawn(async move {
flush_sync().await;
state.set(UseFutureState::Pending); state.set(UseFutureState::Pending);
fut.await; fut.await;
state.set(UseFutureState::Ready); 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())); let task = use_hook(|| CopyValue::new(callback.call()));
// Early returns in dioxus have consequences for use_memo, use_resource, and use_future, etc // Early returns in dioxus have consequences for use_memo, use_resource, and use_future, etc
-2
View File
@@ -135,8 +135,6 @@ where
spawn(async move { spawn(async move {
loop { loop {
// Wait for the dom the be finished with sync work
flush_sync().await;
rc.changed().await; rc.changed().await;
let new = rc.run_in(|| f(dependencies_signal.read().clone())); let new = rc.run_in(|| f(dependencies_signal.read().clone()));
+1 -2
View File
@@ -3,7 +3,7 @@ use crate::{
ReadOnlySignal, ReadableRef, ReadOnlySignal, ReadableRef,
}; };
use dioxus_core::{ use dioxus_core::{
prelude::{flush_sync, spawn, IntoAttributeValue}, prelude::{spawn, IntoAttributeValue},
ScopeId, ScopeId,
}; };
use generational_box::{AnyStorage, Storage, SyncStorage, UnsyncStorage}; use generational_box::{AnyStorage, Storage, SyncStorage, UnsyncStorage};
@@ -109,7 +109,6 @@ impl<T: PartialEq + 'static> Signal<T> {
spawn(async move { spawn(async move {
loop { loop {
flush_sync().await;
rc.changed().await; rc.changed().await;
let new = f(); let new = f();
if new != *state.peek() { if new != *state.peek() {