re export renderers in dioxus
This commit is contained in:
1 parent
b291a5c0b0
commit
af1749d7be
61 files changed
+860
-100
No files matched your search
@@ -34,7 +34,7 @@ The `dioxus` crate exports the `rsx` macro which transforms a helpful, simpler s
|
||||
First, start with your app:
|
||||
|
||||
```rust
|
||||
# use dioxus::core::Mutations;
|
||||
# use dioxus::dioxus_core::Mutations;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
// First, declare a root component
|
||||
|
||||
@@ -73,10 +73,11 @@ 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, DynamicNode, Element, ElementId,
|
||||
Event, Fragment, HasAttributes, IntoDynNode, Mutation, Mutations, NoOpMutations, Properties,
|
||||
RenderReturn, ScopeId, ScopeState, Task, Template, TemplateAttribute, TemplateNode, VComponent,
|
||||
VNode, VNodeInner, VPlaceholder, VText, VirtualDom, WriteMutations,
|
||||
AnyValue, Attribute, AttributeValue, CapturedError, Component, ComponentFunction, DynamicNode,
|
||||
Element, ElementId, Event, Fragment, HasAttributes, IntoDynNode, Mutation, Mutations,
|
||||
NoOpMutations, Properties, RenderReturn, ScopeId, ScopeState, Task, Template,
|
||||
TemplateAttribute, TemplateNode, VComponent, VNode, VNodeInner, VPlaceholder, VText,
|
||||
VirtualDom, WriteMutations,
|
||||
};
|
||||
|
||||
/// The purpose of this module is to alleviate imports of many common types
|
||||
|
||||
@@ -113,8 +113,10 @@ where
|
||||
///
|
||||
/// > Note: If you get an error about the `ComponentFunction` trait not being implemented: make sure your props implements the `Properties` trait or if you would like to declare your props inline, make sure you use the #[component] macro on your function.
|
||||
pub trait ComponentFunction<P> {
|
||||
/// The props type for this component.
|
||||
type Props: 'static;
|
||||
|
||||
/// Run the component function with the given props.
|
||||
fn call(&self, props: Self::Props) -> Element;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,6 +147,23 @@ impl ScopeContext {
|
||||
}
|
||||
}
|
||||
|
||||
/// Inject a Box<dyn Any> into the context of this scope
|
||||
pub(crate) fn provide_any_context(&self, mut value: Box<dyn Any>) {
|
||||
let mut contexts = self.shared_contexts.borrow_mut();
|
||||
|
||||
// If the context exists, swap it out for the new value
|
||||
for ctx in contexts.iter_mut() {
|
||||
// Swap the ptr directly
|
||||
if ctx.as_ref().type_id() == value.as_ref().type_id() {
|
||||
std::mem::swap(ctx, &mut value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Else, just push it
|
||||
contexts.push(value);
|
||||
}
|
||||
|
||||
/// Expose state to children further down the [`crate::VirtualDom`] Tree. Requires `Clone` on the context to allow getting values down the tree.
|
||||
///
|
||||
/// This is a "fundamental" operation and should only be called during initialization of a hook.
|
||||
|
||||
@@ -325,6 +325,14 @@ impl VirtualDom {
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the virtualdom with a global context inserted into the base scope
|
||||
///
|
||||
/// This method is useful for when you want to provide a context in your app without knowing its type
|
||||
pub fn with_boxed_root_context(self, context: Box<dyn Any>) -> Self {
|
||||
self.base_scope().context().provide_any_context(context);
|
||||
self
|
||||
}
|
||||
|
||||
/// Manually mark a scope as requiring a re-render
|
||||
///
|
||||
/// Whenever the Runtime "works", it will re-render this scope
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! This tests to ensure we clean it up
|
||||
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! This methods all use "rebuild_to_vec" which completely bypasses the scheduler.
|
||||
//! Hard rebuild_to_vecs don't consume any events from the event queue.
|
||||
|
||||
use dioxus::core::Mutation::*;
|
||||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// use dioxus::core::Mutation::*;
|
||||
// use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Do we create fragments properly across complex boundaries?
|
||||
|
||||
use dioxus::core::Mutation::*;
|
||||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::Mutation::*;
|
||||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::Mutation::*;
|
||||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// As we clean up old templates, the ID for the node should cycle
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// When returning sets of components, we do a light diff of the contents to preserve some react-like functionality
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::Mutation::*;
|
||||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{ElementId, NoOpMutations};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! It does not validated that component lifecycles work properly. This is done in another test file.
|
||||
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// Should result in moves, but not removals or additions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus::core::{ElementId, Mutation};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn basic_syntax_is_a_template() -> Element {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
//! Tests for the lifecycle of components.
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_html::SerializedHtmlEventConverter;
|
||||
use std::rc::Rc;
|
||||
|
||||
Reference in new issue
Block a user