clean up prelude (#4416)
* clear away prelude on dioxus * clippy * wip - drop prelude from dioxus-html * docs clippy * wip * more fixe * delete all preludes * doc... * better export * merge some imports * fewer global imports * global incremental renderer * fix cargo doc
This commit is contained in:
1 parent
54d465a7b5
commit
4f1d039bad
140 files changed
+374
-477
No files matched your search
@@ -4,8 +4,7 @@
|
||||
|
||||
```rust, no_run
|
||||
# tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
use dioxus_core::prelude::*;
|
||||
use dioxus_core::*;
|
||||
use dioxus_core::{VirtualDom, Event, Element, Mutations};
|
||||
|
||||
let mut vdom = VirtualDom::new(app);
|
||||
let real_dom = SomeRenderer::new();
|
||||
|
||||
@@ -10,10 +10,9 @@ use crate::{
|
||||
VComponent, WriteMutations,
|
||||
},
|
||||
nodes::{AsVNode, VNode},
|
||||
prelude::SuspenseContext,
|
||||
scopes::ScopeId,
|
||||
virtual_dom::VirtualDom,
|
||||
Element,
|
||||
Element, SuspenseContext,
|
||||
};
|
||||
|
||||
impl VirtualDom {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use crate::{
|
||||
prelude::current_scope_id, properties::SuperFrom, runtime::RuntimeGuard, Runtime, ScopeId,
|
||||
};
|
||||
use crate::{current_scope_id, properties::SuperFrom, runtime::RuntimeGuard, Runtime, ScopeId};
|
||||
use generational_box::GenerationalBox;
|
||||
use std::{any::Any, cell::RefCell, marker::PhantomData, panic::Location, rc::Rc};
|
||||
|
||||
@@ -337,7 +335,7 @@ impl<Ret> SpawnIfAsync<(), Ret> for Ret {
|
||||
pub struct AsyncMarker;
|
||||
impl<F: std::future::Future<Output = ()> + 'static> SpawnIfAsync<AsyncMarker> for F {
|
||||
fn spawn(self) {
|
||||
crate::prelude::spawn(async move {
|
||||
crate::spawn(async move {
|
||||
self.await;
|
||||
});
|
||||
}
|
||||
@@ -353,9 +351,9 @@ where
|
||||
{
|
||||
#[inline]
|
||||
fn spawn(self) {
|
||||
crate::prelude::spawn(async move {
|
||||
crate::spawn(async move {
|
||||
if let Err(err) = self.await {
|
||||
crate::prelude::throw_error(err)
|
||||
crate::throw_error(err)
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -366,7 +364,7 @@ impl SpawnIfAsync<()> for crate::Result<()> {
|
||||
#[inline]
|
||||
fn spawn(self) {
|
||||
if let Err(err) = self {
|
||||
crate::prelude::throw_error(err)
|
||||
crate::throw_error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::prelude::SuspenseContext;
|
||||
use crate::runtime::RuntimeError;
|
||||
use crate::{innerlude::SuspendedFuture, runtime::Runtime, CapturedError, Element, ScopeId, Task};
|
||||
use crate::{
|
||||
innerlude::SuspendedFuture, runtime::Runtime, CapturedError, Element, ScopeId, SuspenseContext,
|
||||
Task,
|
||||
};
|
||||
use std::future::Future;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -18,7 +20,7 @@ pub fn vdom_is_rendering() -> bool {
|
||||
Runtime::with(|rt| rt.rendering.get()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Throw a [`CapturedError`] into the current scope. The error will bubble up to the nearest [`crate::prelude::ErrorBoundary()`] or the root of the app.
|
||||
/// Throw a [`CapturedError`] into the current scope. The error will bubble up to the nearest [`crate::ErrorBoundary()`] or the root of the app.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rust, no_run
|
||||
|
||||
+14
-26
@@ -77,32 +77,20 @@ pub(crate) mod innerlude {
|
||||
}
|
||||
|
||||
pub use crate::innerlude::{
|
||||
fc_to_builder, generation, schedule_update, schedule_update_any, use_hook, vdom_is_rendering,
|
||||
AnyValue, Attribute, AttributeValue, CapturedError, Component, ComponentFunction, DynamicNode,
|
||||
Element, ElementId, Event, Fragment, HasAttributes, IntoDynNode, LaunchConfig,
|
||||
ListenerCallback, MarkerWrapper, Mutation, Mutations, NoOpMutations, Ok, Properties, Result,
|
||||
Runtime, ScopeId, ScopeState, SpawnIfAsync, Task, Template, TemplateAttribute, TemplateNode,
|
||||
VComponent, VNode, VNodeInner, VPlaceholder, VText, VirtualDom, WriteMutations,
|
||||
consume_context, consume_context_from_scope, current_owner, current_scope_id, fc_to_builder,
|
||||
force_all_dirty, generation, has_context, needs_update, needs_update_any, parent_scope,
|
||||
provide_context, provide_error_boundary, provide_root_context, queue_effect, remove_future,
|
||||
schedule_update, schedule_update_any, spawn, spawn_forever, spawn_isomorphic, suspend,
|
||||
suspense_context, throw_error, try_consume_context, use_after_render, use_before_render,
|
||||
use_drop, use_hook, use_hook_with_cleanup, vdom_is_rendering, with_owner, AnyValue, Attribute,
|
||||
AttributeValue, Callback, CapturedError, Component, ComponentFunction, Context, DynamicNode,
|
||||
Element, ElementId, ErrorBoundary, ErrorContext, Event, EventHandler, Fragment, HasAttributes,
|
||||
IntoAttributeValue, IntoDynNode, LaunchConfig, ListenerCallback, MarkerWrapper, Mutation,
|
||||
Mutations, NoOpMutations, Ok, OptionStringFromMarker, Properties, ReactiveContext, RenderError,
|
||||
Result, Runtime, RuntimeGuard, ScopeId, ScopeState, SpawnIfAsync, SuperFrom, SuperInto,
|
||||
SuspendedFuture, SuspenseBoundary, SuspenseBoundaryProps, SuspenseContext, SuspenseExtension,
|
||||
Task, Template, TemplateAttribute, TemplateNode, VComponent, VNode, VNodeInner, VPlaceholder,
|
||||
VText, VirtualDom, WriteMutations,
|
||||
};
|
||||
|
||||
/// The purpose of this module is to alleviate imports of many common types
|
||||
///
|
||||
/// This includes types like [`Element`], and [`Component`].
|
||||
pub mod prelude {
|
||||
pub use crate::innerlude::{
|
||||
consume_context, consume_context_from_scope, current_owner, current_scope_id,
|
||||
fc_to_builder, force_all_dirty, generation, has_context, needs_update, needs_update_any,
|
||||
parent_scope, provide_context, provide_error_boundary, provide_root_context, queue_effect,
|
||||
remove_future, spawn, spawn_forever, spawn_isomorphic, suspend, suspense_context,
|
||||
throw_error, try_consume_context, use_after_render, use_before_render, use_drop, use_hook,
|
||||
use_hook_with_cleanup, with_owner, AnyValue, Attribute, Callback, Component,
|
||||
ComponentFunction, Context, Element, ErrorBoundary, ErrorContext, Event, EventHandler,
|
||||
Fragment, HasAttributes, IntoAttributeValue, IntoDynNode, OptionStringFromMarker,
|
||||
Properties, ReactiveContext, RenderError, Runtime, RuntimeGuard, ScopeId, ScopeState,
|
||||
SuperFrom, SuperInto, SuspendedFuture, SuspenseBoundary, SuspenseBoundaryProps,
|
||||
SuspenseContext, SuspenseExtension, Task, Template, TemplateAttribute, TemplateNode, VNode,
|
||||
VNodeInner, VirtualDom,
|
||||
};
|
||||
}
|
||||
|
||||
pub use const_format;
|
||||
@@ -1,15 +1,12 @@
|
||||
use dioxus_core_types::DioxusFormattable;
|
||||
|
||||
use crate::events::ListenerCallback;
|
||||
use crate::innerlude::VProps;
|
||||
use crate::prelude::RenderError;
|
||||
use crate::{any_props::BoxedAnyProps, innerlude::ScopeState};
|
||||
use crate::{arena::ElementId, Element, Event};
|
||||
use crate::{
|
||||
innerlude::{ElementRef, MountId},
|
||||
any_props::BoxedAnyProps,
|
||||
arena::ElementId,
|
||||
events::ListenerCallback,
|
||||
innerlude::{ElementRef, MountId, ScopeState, VProps},
|
||||
properties::ComponentFunction,
|
||||
Element, Event, Properties, RenderError, ScopeId, VirtualDom,
|
||||
};
|
||||
use crate::{Properties, ScopeId, VirtualDom};
|
||||
use dioxus_core_types::DioxusFormattable;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::vec;
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
use crate::{
|
||||
prelude::{current_scope_id, ScopeId},
|
||||
scope_context::Scope,
|
||||
tasks::SchedulerMsg,
|
||||
Runtime,
|
||||
};
|
||||
use crate::{current_scope_id, scope_context::Scope, tasks::SchedulerMsg, Runtime, ScopeId};
|
||||
use futures_channel::mpsc::UnboundedReceiver;
|
||||
use generational_box::{BorrowMutError, GenerationalBox, SyncStorage};
|
||||
use std::{
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::{prelude::*, properties::RootProps, DynamicNode, VComponent};
|
||||
use crate::{
|
||||
fc_to_builder, properties::RootProps, DynamicNode, Element, ErrorBoundary, Properties,
|
||||
SuspenseBoundary, Template, TemplateNode, VComponent, VNode,
|
||||
};
|
||||
|
||||
// We wrap the root scope in a component that renders it inside a default ErrorBoundary and SuspenseBoundary
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use crate::innerlude::{throw_error, RenderError, ScopeOrder};
|
||||
use crate::nodes::AsVNode;
|
||||
use crate::prelude::ReactiveContext;
|
||||
use crate::scope_context::SuspenseLocation;
|
||||
use crate::{
|
||||
any_props::{AnyProps, BoxedAnyProps},
|
||||
innerlude::ScopeState,
|
||||
scope_context::Scope,
|
||||
innerlude::{throw_error, RenderError, ScopeOrder, ScopeState},
|
||||
nodes::AsVNode,
|
||||
scope_context::{Scope, SuspenseLocation},
|
||||
scopes::ScopeId,
|
||||
virtual_dom::VirtualDom,
|
||||
ReactiveContext,
|
||||
};
|
||||
use crate::{Element, VNode};
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use crate::runtime::RuntimeError;
|
||||
use crate::{innerlude::SchedulerMsg, Runtime, ScopeId, Task};
|
||||
use crate::{
|
||||
innerlude::{throw_into, CapturedError},
|
||||
prelude::SuspenseContext,
|
||||
innerlude::{throw_into, CapturedError, SchedulerMsg, SuspenseContext},
|
||||
runtime::RuntimeError,
|
||||
Runtime, ScopeId, Task,
|
||||
};
|
||||
use generational_box::{AnyStorage, Owner};
|
||||
use rustc_hash::FxHashSet;
|
||||
@@ -159,7 +158,7 @@ impl Scope {
|
||||
|
||||
/// Schedule an update for any component given its [`ScopeId`].
|
||||
///
|
||||
/// A component's [`ScopeId`] can be obtained from `use_hook` or the [`current_scope_id`](crate::prelude::current_scope_id) method.
|
||||
/// A component's [`ScopeId`] can be obtained from `use_hook` or the [`current_scope_id`](crate::current_scope_id) method.
|
||||
///
|
||||
/// This method should be used when you want to schedule an update for a component.
|
||||
///
|
||||
@@ -612,7 +611,7 @@ impl ScopeId {
|
||||
.on_scope(self, f)
|
||||
}
|
||||
|
||||
/// Throw a [`CapturedError`] into a scope. The error will bubble up to the nearest [`ErrorBoundary`](crate::prelude::ErrorBoundary) or the root of the app.
|
||||
/// Throw a [`CapturedError`] into a scope. The error will bubble up to the nearest [`ErrorBoundary`](crate::ErrorBoundary) or the root of the app.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rust, no_run
|
||||
|
||||
@@ -33,7 +33,7 @@ impl std::fmt::Debug for ScopeId {
|
||||
}
|
||||
|
||||
impl ScopeId {
|
||||
/// The ScopeId of the main scope passed into [`crate::prelude::VirtualDom::new`].
|
||||
/// The ScopeId of the main scope passed into [`crate::VirtualDom::new`].
|
||||
///
|
||||
/// This scope will last for the entire duration of your app, making it convenient for long-lived state
|
||||
/// that is created dynamically somewhere down the component tree.
|
||||
@@ -51,7 +51,7 @@ impl ScopeId {
|
||||
pub const APP: ScopeId = ScopeId(3);
|
||||
|
||||
/// The ScopeId of the topmost scope in the tree.
|
||||
/// This will be higher up in the tree than [`ScopeId::APP`] because dioxus inserts a default [`crate::prelude::SuspenseBoundary`] and [`crate::prelude::ErrorBoundary`] at the root of the tree.
|
||||
/// This will be higher up in the tree than [`ScopeId::APP`] because dioxus inserts a default [`crate::SuspenseBoundary`] and [`crate::ErrorBoundary`] at the root of the tree.
|
||||
// ScopeId(0) is the root scope wrapper
|
||||
pub const ROOT: ScopeId = ScopeId(0);
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
//!
|
||||
//! This tests to ensure we clean it up
|
||||
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{generation, ElementId, IntoAttributeValue, Mutation::*};
|
||||
|
||||
#[test]
|
||||
fn attrs_cycle() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::TemplateNode;
|
||||
|
||||
/// Make sure that rsx! is parsing templates and their attributes properly
|
||||
#[test]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! we should properly bubble up errors from components
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
fn app() -> Element {
|
||||
let raw = match generation() % 2 {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use std::{sync::atomic::AtomicUsize, time::Duration};
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
#[tokio::test]
|
||||
async fn child_futures_drop_first() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
#[test]
|
||||
fn state_shares() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
/// As we clean up old templates, the ID for the node should cycle
|
||||
#[test]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::dioxus_core::{AttributeValue, ElementId, NoOpMutations};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
#[test]
|
||||
fn text_diff() {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
/// Should result in moves, but not removals or additions
|
||||
#[test]
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::collections::HashSet;
|
||||
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::Mutation;
|
||||
use dioxus_core::{generation, Mutation};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use dioxus::dioxus_core::{ElementId, Mutation};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::IntoAttributeValue;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn basic_syntax_is_a_template() -> Element {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::generation;
|
||||
|
||||
#[test]
|
||||
fn app_drops() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::NoOpMutations;
|
||||
use dioxus_core::{generation, NoOpMutations};
|
||||
|
||||
/// This test checks that we should release all memory used by the virtualdom when it exits.
|
||||
///
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{AttributeValue, ElementId, Mutation};
|
||||
use dioxus_core::{generation, AttributeValue, ElementId, Mutation};
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::future::poll_fn;
|
||||
use std::task::Poll;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use std::{sync::atomic::AtomicUsize, time::Duration};
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{generation, needs_update, spawn_forever};
|
||||
|
||||
async fn run_vdom(app: fn() -> Element) {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use dioxus::html::SerializedHtmlEventConverter;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
use dioxus_core::{ElementId, Event};
|
||||
use std::{any::Any, rc::Rc};
|
||||
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer};
|
||||
use tracing_subscriber::{layer::SubscriberExt, Registry};
|
||||
|
||||
Reference in new issue
Block a user