text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
use crate::{Runtime, ScopeId, current_scope_id, properties::SuperFrom, runtime::RuntimeGuard};
use futures_util::FutureExt;
use generational_box::GenerationalBox;
use std::{any::Any, cell::RefCell, marker::PhantomData, panic::Location, rc::Rc};
/// A wrapper around some generic data that handles the event's state
///
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> its parent, even if the component's
/// props are valid for the static lifetime.
///
/// ## Example
///
/// ```rust
/// # use dioxus::prelude::*;
/// fn app() -> Element {
/// rsx! {
/// CustomCard {
/// h1 {}
/// p {}
/// }
/// }
/// }
///
/// #[component]... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Integration with the generational-box crate for copy state management.
//!
//! Each scope in dioxus has a single [Owner]
use generational_box::{AnyStorage, Owner, SyncStorage, UnsyncStorage};
use std::{
any::{Any, TypeId},
cell::RefCell,
};
/// Run a closure with the given owner.
///
/// Thi... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>alue.clone();
use_drop(move || cleanup(_value));
value
}
<|fim_prefix|>use crate::innerlude::CapturedError;
use crate::{Element, ScopeId, Task, innerlude::SuspendedFuture, runtime::Runtime};
use std::future::Future;
use std::rc::Rc;
use std::sync::Arc;
/// Get the current scope id
pub fn current_... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::{
any::{Any, TypeId},
hash::{Hash, Hasher},
};
#[cfg(feature = "serialize")]
use crate::nodes::deserialize_string_leaky;
use crate::{
Attribute, AttributeValue, DynamicNode, Template, TemplateAttribute, TemplateNode, VNode, VText,
};
#[cfg_attr(feature = "serialize", derive(serde::S... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! This module contains utiliti<|fim_suffix|> for () {}
<|fim_middle|>es renderers use to integrate with the launch function.
/// A marker trait for platform configs. We use this marker to
/// make sure that the user doesn't accidentally pass in a config
/// builder instead of the config
pub trait Launc... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
#![warn(missing_docs)]
mod any_props;
mod arena;
mod diff;
mod effect;
mod error_boundary;
mod events;
mod frag... | fim | DioxusLabs/dioxus | rust |
use crate::{AttributeValue, Template, arena::ElementId};
/// Something that can handle the mutations that are generated by the diffing process and apply them to the Real DOM
///
/// This object provides a bunch of important information for a renderer to use patch the Real Dom with the state of the
/// VirtualDom. This... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>sume this item and produce a DynamicNode
fn into_dyn_node(self) -> DynamicNode;
}
impl IntoDynNode for () {
fn into_dyn_node(self) -> DynamicNode {
DynamicNode::default()
}
}
impl IntoDynNode for VNode {
fn into_dyn_node(self) -> DynamicNode {
DynamicNode::Fragment(vec![se... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::fmt::Arguments;
use crate::innerlude::*;
/// Every "Props" used for a component must implement the `Properties` trait. This trait gives some hints to Dioxus
/// on how to memoize the props and some additional optimizations that can be made. We strongly encourage using the
/// derive macro to im... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{Runtime, ScopeId, current_scope_id, scope_context::Scope, tasks::SchedulerMsg};
use futures_channel::mpsc::UnboundedReceiver;
use generational_box::{BorrowMutError, GenerationalBox, SyncStorage};
use std::{
cell::RefCell,
collections::HashSet,
hash::Hash,
sync::{Arc, Mutex},
};... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::{
fmt::{Debug, Display},
sync::Arc,
};
use crate::innerlude::*;
/// An error that can occur while rendering a component
#[derive(Debug, Clone, PartialEq)]
pub enum RenderError {
/// The render function returned early due to an error.
///
/// We captured the error, wrapped it... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> )))
.build()
.into_vcomponent(SuspenseBoundary),
)]),
Box::new([]),
))
}
<|fim_prefix|>use crate::{
DynamicNode, Element, ErrorBoundary, Properties, SuspenseBoundary, Template, TemplateNode,
VComponent, VNode, fc_to_builder, propert... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> // Break if this is the exact target element.
// This means we won't call two listeners with the same name on the same element. This should be
// documented, or be rejected from the rsx! macro outright
if target_... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>t.order.id.0));
Some(effect)
}
/// Take any work from the highest scope. This may include rerunning the scope and/or running tasks
pub(crate) fn pop_work(&mut self) -> Option<Work> {
let dirty_scope = self.dirty_scopes.first();
// Make sure the top dirty scope is vali... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>uspend(boundary.clone());
if !already_suspended {
tracing::trace!("Suspending {:?} on {:?}", scope.id, task);
// Add this task to the suspended tasks list of the boundary
if let SuspenseLocation::UnderSuspense(boundary) = &boundar... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{
Runtime, ScopeId, Task,
innerlude::{SchedulerMsg, SuspenseContext},
};
use generational_box::{AnyStorage, Owner};
use rustc_hash::FxHashSet;
use std::{
any::Any,
cell::{Cell, RefCell},
future::Future,
sync::Arc,
};
pub(crate) enum ScopeStatus {
Mounted,
Unmoun... | fim | DioxusLabs/dioxus | rust |
use crate::{
Element, RenderError, Runtime, VNode, any_props::BoxedAnyProps,
reactive_context::ReactiveContext, scope_context::Scope,
};
use std::{cell::Ref, rc::Rc};
/// A component's unique identifier.
///
/// `ScopeId` is a `usize` that acts a key for the internal slab of Scopes. This means that the key is ... | fim | DioxusLabs/dioxus | rust |
use crate::{innerlude::*, scope_context::SuspenseLocation};
/// Properties for the [`SuspenseBoundary()`] component.
#[allow(non_camel_case_types)]
pub struct SuspenseBoundaryProps {
fallback: Callback<SuspenseContext, Element>,
/// The children of the suspense boundary
children: LastRenderedNode,
}
impl ... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>d_tasks", &self.suspended_tasks)
.field("id", &self.id)
.field("suspended_nodes", &self.suspended_nodes)
.field("frozen", &self.frozen)
.finish()
}
}
<|fim_prefix|>//! Suspense allows you to render a placeholder while nodes are waiting for data in the ba... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> to be progressed
TaskNotified(slotmap::DefaultKey),
/// An effect has been queued to run after the next render
EffectQueued,
}
struct LocalTaskHandle {
id: slotmap::DefaultKey,
tx: futures_channel::mpsc::UnboundedSender<SchedulerMsg>,
}
impl ArcWake for LocalTaskHandle {
fn wak... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! # Virtual DOM Implementation for Rust
//!
//! This module provides the primary mechanics to create a hook-based, concurrent VDOM for Rust.
use crate::properties::RootProps;
use crate::root_wrapper::RootScopeWrapper;
use crate::{
ComponentFunction, Element, Mutations,
arena::ElementId,
inn... | fim | DioxusLabs/dioxus | rust |
//! dynamic attributes in dioxus necessitate an allocated node ID.
//!
//! This tests to ensure we clean it up
use dioxus::prelude::*;
use dioxus_core::{ElementId, IntoAttributeValue, Mutation::*, generation};
#[test]
fn attrs_cycle() {
tracing_subscriber::fmt::init();
let mut dom = VirtualDom::new(|| {
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
use dioxus_core::TemplateNode;
/// Make sure that rsx! is parsing templates and their attributes properly
#[test]
fn attributes_pass_properly() {
let h = rsx! {
circle {
cx: 50,
cy: 50,
r: 40,<|fim_suffix|>mespace, Some("http://www.w... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::dioxus_core::{ElementId, Mutation::*};
use dioxus::prel<|fim_suffix|>
[
LoadTemplate { index: 0, id: ElementId(1) },
SetAttribute {
name: "hidden",
value: dioxus_core::AttributeValue::Bool(false),
id: ElementId(1,)... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Verify that when children are dropped, they drop their futures before they are polled
use std::{sync::atomic::AtomicUsize, time::Duration};
use dioxus::prelude::*;
use dioxus_core::generation;
#[tokio::test]
async fn child_futures_drop_first() {
static POLL_COUNT: AtomicUsize = AtomicUsize::new... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
/// Make sure that rsx! handles conditional attributes with one formatted branch correctly
/// Regression test for https://github.com/DioxusLabs/dioxus/issues/2997. There are no assertions in
/// this test as it primarily checks that the RSX can be compiled correctly.
#[test]
fn p... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>_dirty(ScopeId::APP);
_ = dom.render_immediate_to_vec();
dom.in_runtime(|| {
assert_eq!(consume_context_from_scope::<i32>(ScopeId::APP).unwrap(), 2);
});
dom.mark_dirty(ScopeId(ScopeId::APP.0 + 2));
assert_eq!(
dom.render_immediate_to_vec().edits,
[SetText { va... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![all<|fim_suffix|> div { "hello" }
}
if false {
div { "goodbye" }
}
}
});
// note that the template under "false" doesn't show up since it's not loaded
let edits = dom.rebuild_to_vec();
// note: we dont test template edits ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Do we create fragments properly across complex boundaries?
use dioxus::dioxus_core::Mutation::*;
use dioxus::prelude::*;
use dioxus_core::ElementId;
#[test]
fn empty_fragment_creates_nothing() {
fn app() -> Element {
rsx!({})
}
let mut vdom = VirtualDom::new(app);
let edits ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::dioxus_core::Mutation::*;
use <|fim_suffix|>ease linearly. This lets us drive a vec on the renderer for O(1) re-indexing
fn app() -> Element {
rsx! {
div {
for i in 0..3 {
div {
h1 { "hello world! "}
p { "{i}" }
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>e { value: "456".to_string(), id: ElementId(2) },
AppendChildren { id: ElementId(0), m: 2 }
]
)
}
<|fim_prefix|>use dioxus::dioxus_core::Mutation::*;
use dioxus::prelude::*;
use dioxus_core::ElementId;
/// Should push the text node onto the stack and modify it
#[test]
fn nested_pa... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ReplaceWith { id: ElementId(1,), m: 1 },
]
);
}
<|fim_prefix|>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]
fn cycling_elements() {
let mut dom = VirtualDom... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::dioxus_core::{ElementId, Mutation::*};
use dioxus::prelude::*;
use pretty_asser<|fim_suffix|>ard {}
},
_ => rsx!("blah"),
}
}
fn nav_bar() -> Element {
rsx! {
h1 {
"NavBar"
for _ in 0..3 {
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ender_immediate_to_vec().edits,
[
CreateTextNode { value: "true".to_string(), id: ElementId(1) },
ReplaceWith { id: ElementId(2), m: 1 },
]
);
}
<|fim_prefix|>use dioxus::dioxus_core::{ElementId, Mutation::*};
use dioxus::prelude::*;
use dioxus_core::generation;... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::dioxus_core::Mut<|fim_suffix|>r_immediate_to_vec().edits,
[
SetAttribute { name: "c", value: AttributeValue::None, id: ElementId(1,), ns: None },
SetAttribute {
name: "d",
value: AttributeValue::Text("world".into()),
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Diffing Tests
//!
//! These tests only verify that the diffing algorithm works properly for single components.
//!
//! It does not validate that component lifecycles work properly. This is done in another test file.
use dioxus::dioxus_core::{ElementId, Mutation::*};
use dioxus::prelude::*;
use dioxus... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>render_immediate_to_vec();
assert_eq!(
edits.edits,
[
// load the p tag template
LoadTemplate { index: 0, id: ElementId(5) },
// Create the third text node
CreateTextNode { value: "3".into(), id: ElementId(6) }... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(non_snake_case)]
use dioxus::{CapturedError, prelude::*};
#[test]
fn catches_panic() {
let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations);
}
fn app() -> Element {
rsx! {
div {
h1 { "Title" }
NoneChild {}
Thr... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> },
{vec![
rsx! {
problematic_child {}
}
].into_iter()}
}
}
}
fn problematic_child() -> Element {
rsx! {
button { onclick: move |evt| {
println!("bottom clicked");
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>, _: ElementId) {}
fn push_root(&mut self, _: ElementId) {}
}
<|fim_prefix|>#![cfg(not(miri))]
use dioxus::prelude::*;
use dioxus_core::{AttributeValue, DynamicNode, NoOpMutations, Template, VComponent, VNode, *};
use std::{any::Any, cell::RefCell, cfg, collections::HashSet, default::Default, rc::Rc... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>enabling hotreloading
<|fim_prefix|>//! It should be possible <|fim_middle|>to swap out templates at runtime, <|endoftext|> | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>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 {
let asd = 123;
let var = 123;
rsx! {
div {
key: "{asd}",
class: "asd",
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ed<T> = Arc<Mutex<T>>;
#[test]
fn manual_diffing() {
#[derive(Clone)]
struct AppProps {
value: Shared<&'static str>,
}
fn app(cx: AppProps) -> Element {
let val = cx.value.lock().unwrap();
rsx! { div { "{val}" } }
};
let value = Arc::new(Mutex::new("Hello... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>e div to the dom
AppendChildren { m: 1, id: ElementId(0) },
]
)
}
<|fim_prefix|>#![allow(non_snake_case)]
use dioxus::dioxus_core::Mutation::*;
use dioxus::prelude::*;
use dioxus_core::{AttributeValue, ElementId};
use pretty_assertions::assert_eq;
/// Should push the text node on... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(non_snake_case)]
use dioxus::prelude::dioxus_core::NoOpMutations;
use dioxus::prelude::*;
use sysinfo::{ProcessRefreshKind, RefreshKind, System};
// Regression test for https://github.com/DioxusLabs/dioxus/issues/3421
#[tokio::test]
async fn test_for_memory_leaks() {
fn app() -> Element {
... | fim | DioxusLabs/dioxus | rust |
use dioxus::prelude::*;
use dioxus_core::ElementId;
use dioxus_elements::SerializedHtmlEventConverter;
use std::{any::Any, rc::Rc};
// This test is intended to be run with Miri, and contains no assertions. If it completes under
// Miri, it has passed.
#[test]
fn miri_rollover() {
set_event_converter(Box::new(Seria... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>rop() {
fn app() -> Element {
provide_context(String::from("asd"));
rsx! {
div { ChildComp {} }
}
}
#[allow(non_snake_case)]
fn ChildComp() -> Element {
let el = consume_context::<String>();
rsx! { div { "hello {el}" } }
}
let... | fim | DioxusLabs/dioxus | rust |
#![allow(non_snake_case)]
use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_core::{NoOpMutations, generation};
// The tests in this file are intended to be run with Miri, so not all of them contain assertions.
// If the tests complete under Miri, they have passed.
/// This test checks that we should release all ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Tests related to safety of the library.
use dioxus::prelude::*;
/// Ensure no issues with not calling rebuild_to_vec
#[test]
fn root_node_isnt_null() {
let dom = VirtualDom::new(|| rsx!("Hello world!"));
let scope = dom.base_scope();
// We haven't built the tr<|fim_suffix|> 0);
});... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> 3,
),
m: 3,
},
// Replace the second loading placeholder with a placeholder for us to fill in later
CreatePlaceholder {
id: ElementId(
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Verify that tasks get polled by the virtualdom properly, and that we escape wait_for_work safely
<|fim_suffix|>) {
use std::sync::atomic::Ordering;
static POLL_COUNT: AtomicUsize = AtomicUsize::new(0);
fn app() -> Element {
if generation() > 0 {
rsx!(div {})
} ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::html::SerializedHtmlEventConverter;
use dioxus::prelude::*;
use dioxus_core::{ElementId, Event};
use std::{any::Any, rc::Rc};
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer};
use tracing_subscriber::{Registry, layer::SubscriberExt};
#[test]
fn basic_tracing() {
// setu... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> app,
AppProps { drop_count: drop_count.clone(), render_child: render_child.clone() },
);
dom.rebuild_in_place();
assert_eq!(*drop_count.lock().unwrap(), 0);
*render_child.lock().unwrap() = false;
dom.mark_dirty(ScopeId::APP);
dom.render_immediate(&mut dioxus_core::... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt, format_ident, quote};
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::*;
pub struct ComponentBody {
pub item_fn: ItemFn,
pub options: ComponentMacroOptions,
}
impl Parse... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>doc = include_str!("../docs/rsx.md")]
#[proc_macro]
pub fn rsx(tokens: TokenStream) -> TokenStream {
match syn::parse::<rsx::CallBody>(tokens) {
Err(err) => err.to_compile_error().into(),
Ok(body) => body.into_token_stream().into(),
}
}
#[doc = include_str!("../docs/component.md")... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> // The default of a field can refer to earlier-defined fields, which we handle by
// writing out a bunch of `let` statements first, which can each refer to earlier ones.
// This means that field ordering may actually be significant, which isn’t ideal. We could
//... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use quote::ToTokens;
use syn::parse::{Parse, ParseStream};
use syn::spanned::Spanned;
use syn::{Expr, Lit, Meta, Token, Type, parse_quote};
/// Attempts to convert the given literal to a string.
/// Converts ints and floats to their base 10 counterparts.<|fim_suffix|>rim().to_string()),
}... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
// This test just checks that event handlers compile without explicit type annotations
// It will not actually run any code
#[test]
#[allow(unused)]
fn event_handlers_compile() {
fn app() -> Element {
let mut todos = use_signal(String::new);
rsx! {
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::{fmt::Display, marke<|fim_suffix|> fn TakesCloneMyBox<T: 'static>(value: MyBox<T>) -> Element
where
T: Display,
{
rsx! {}
}
#[derive(Props, Clone, PartialEq)]
struct TakesCloneManualProps<T: Clone + PartialEq + 'static> {
value: T,
}
fn Take... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>// G<|fim_suffix|>ve span.
use dioxus::prelude::*;
fn main() {
rsx! {
p {
class: "foo bar"
"Hello world"
}
};
}
<|fim_middle|>iven an `rsx!` invocation with a missing trailing comma,
// ensure the stderr output has an informati<|endoftext|> | fim | DioxusLabs/dioxus | rust |
#[test]
fn rsx() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/rsx/trailing-comma-0.rs");
}
/// This test ensures that automatic `into` conversion occurs for default values.
///
/// These are compile-time tests.
/// See https://github.com/DioxusLabs/dioxus/issues/2373
#[cfg(test)]
mod test_defaul... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::{
core::{generation, needs_update},
prelude::*,
};
use dioxus_core::ElementId;
use std::{any::Any, rc::Rc};
#[tokio::test]
async fn values_memoize_in_place() {
thread_local! {
static DROP_COUNT: std::cell::RefCell<usize> = const { std::cell::RefCell::new(0) };
}
s... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> false,
"canplay" => false,
"canplaythrough" => false,
"durationchange" => false,
"emptied" => false,
"encrypted" => true,
"ended" => false,
"error" => false,
"loadeddata" => false,
"loadedmetadata" => false,
"loadstart" => fa... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::sync::LazyLock;
pub fn is_bundled_app() -> bool {
static BUNDLED: LazyLock<bool> = LazyLock::new(|| {
// If the env var is set, we're bundled
if std::env::var("DIOXUS_CLI_ENABLED").is_ok() {
return true;
}
// If the cargo manifest dir is set, we'r... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>this just with Display.
pub trait DioxusFormattable {
fn format(&self) -> Cow<'static, str>;
}
<|fim_prefix|>use std::borrow::Cow;
/// Take this type and format it into a Cow<'static, str>
///
/// Thi<|fim_middle|>s trait exists so libraries like manganis can implement this type for assets without de... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>tr) -> Option<(&'static str, Option<&'static str>)>;
}
pub struct Empty;
impl HotReloadingContext for Empty {
fn map_attribute(_: &str, _: &str) -> Option<(&'static str, Option<&'static str>)> {
None
}
fn map_element(_: &str) -> Option<(&'static str, Option<&'static str>)> {
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>t::*;
<|fim_prefix|>pub mod bubbles;
pub mod bundled;
pub mod formatter;
pub mod hr_context;
pub use bubbles::*;
pub use bundled::*;
pub use form<|fim_middle|>atter::*;
pub use hr_contex<|endoftext|> | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> "/dioxus/packages/html/src/file_data.rs",
"/dioxus/packages/html/src/geometry.rs",
"/dioxus/packages/html/src/input_data.rs",
"/dioxus/packages/html/src/lib.rs",
"/dioxus/packages/html/src/point_interaction.rs",
"/dioxus/packages/html/src/r... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>e
[[example]]
name = "suspense"
path = "../../examples/suspense.rs"
doc-scrape-examples = true
[[example]]
name = "calculator_mutable"
path = "../../examples/calculator_mutable.rs"
doc-scrape-examples = true
[[example]]
name = "custom_html"
path = "../../examples/custom_html.rs"
doc-scrape-examples = t... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
use dioxus_desktop::window;
use serde::Deserialize;
#[path = "./utils.rs"]
mod utils;
pub fn main() {
#[cfg(not(windows))]
utils::check_a<|fim_suffix|> assert_eq!(
Vec::<i32>::deserialize(&eval.await.unwrap()).unwrap(),
vec![1, 2, 3]
)... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::html::geometry::euclid::Vector3D;
use dioxus::prelude::*;
use dioxus_desktop::DesktopContext;
#[path = "./utils.rs"]
mod utils;
pub fn main() {
#[cfg(not(windows))]
utils::check_app_exits(app);
}
static RECEIVED_EVENTS: GlobalSignal<usize> = Signal::global(|| 0);
fn app() -> Elemen... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
use dioxus_desktop::DesktopContext;
use dioxus_document::eval;
#[path = "./utils.rs"]
mod utils;
fn main() {
#[cfg(not(windows))]
utils::check_app_exits(check_html_renders);
}
async fn inner_html(count: usize) -> String {
let html = document::eval(&format!(
r... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> input { "type": "checkbox" }
h1 { "text" }
{dyn_element}
}
}
}
}
<|fim_prefix|>use dioxus::prelude::*;
use dioxus_desktop::DesktopContext;
#[path = "./utils.rs"]
mod utils;
fn main() {
#[cfg(not(windows))]
utils::check_app_exit... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>PECTED_EVENTS: GlobalSignal<usize> = Signal::global(|| 0);
pub fn mock_event(id: &'static str, value: &'static str) {
mock_event_with_extra(id, value, "");
}
pub fn mock_event_with_extra(id: &'static str, value: &'static str, extra: &'static str) {
use_hook(move || {
EXPECTED_EVENTS.with... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>/// This is a hack to get around the fact that wry is currently not thread safe on android
///
/// We want to acquire this mutex before doing anything with the virtualdom directly
#[cfg(target_os = "android")]
pub fn android_runtime_lock() -> std::sync::MutexGuard<'static, ()> {
use std::sync::{Mutex,... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>todo: should we unset the event handler when the app shuts down?
_ = receiver.send_event(UserWindowEvent::GlobalHotKeyEvent(t));
}));
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
fn set_menubar_receiver(&self) {
let receiver = self... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus_core::Callback;
use rustc_hash::FxHashMap;
use std::{cell::RefCell, rc::Rc};
use wry::{RequestAsyncResponder, http::Request};
/// A request for an asset within dioxus-desktop.
pub type AssetRequest = Request<Vec<u8>>;
pub struct AssetHandler {
f: Callback<(AssetRequest, RequestAsyncRespon... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>derState::Unset,
protocols: Vec::new(),
asynchronous_protocols: Vec::new(),
pre_rendered: None,
disable_context_menu: !cfg!(debug_assertions),
resource_dir: None,
data_dir: None,
custom_head: None,
custom_index... | fim | DioxusLabs/dioxus | rust |
use anyhow::Result;
use image::GenericImageView;
use image::ImageReader;
use image::load_from_memory;
use std::path::Path;
/// Pre-decoded RGBA bytes of the bundled fallback icon.
const FALLBACK_ICON_RGBA: &[u8] = include_bytes!("./assets/default_icon.bin");
const FALLBACK_ICON_WIDTH: u32 = 460;
const FALLBACK_ICON_HE... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ained;
use objc2_ui_kit::UIView;
let ui_view = self.window.ui_view().cast::<UIView>();
unsafe { Retained::retain(ui_view) }.unwrap()
}
#[cfg(target_os = "ios")]
/// Get a retained reference to the current UIViewController
pub fn ui_view_controller(&self) -> objc2::... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{DesktopContext, WeakDesktopContext, query::Query};
use dioxus_core::queue_effect;
use dioxus_document::{
Document, Eval, EvalError, Evaluator, LinkProps, MetaProps, ScriptProps, StyleProps,
create_element_in_head,
};
use generational_box::{AnyStorage, GenerationalBox, UnsyncStorage};
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> currently waiting for an edit to be flushed. We don't run the virtual dom while this is true to avoid running effects before the dom has been updated
edits_in_progress: Option<oneshot::Receiver<()>>,
// The socket may be killed by the OS while running. If it does, this channel will receive the ne... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> )),
Err(err) => {
MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err)))
}
}
})
}
}
#[derive(Debug)]
enum DesktopQueryError {
FailedToQuery,
}
impl std::fmt::Display for DesktopQueryError... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{ipc::UserWindowEvent, window};
use slab::Slab;
use std::cell::RefCell;
use tao::{event::Event, event_loop::EventLoopWindowTarget, window::WindowId};
/// The unique identifier of a window event handler. This can be used to later remove the handler.
#[derive(Debug, Clone, Copy, PartialEq, Eq, H... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>rap()
.into()
}
fn convert_keyboard_data(&self, event: &PlatformEventData) -> KeyboardData {
event
.downcast::<SerializedKeyboardData>()
.cloned()
.unwrap()
.into()
}
fn convert_media_data(&self, event: &PlatformEventDat... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(unused)]
use std::{any::Any, collections::HashMap};
#[cfg(feature = "tokio_runtime")]
use tokio::{fs::File, io::AsyncReadExt};
use dioxus_html::{
FileData, FormValue, HasDataTransferData, HasDragData, HasFileData, HasFormData, HasMouseData,
NativeFileData, SerializedDataTransfer, Seria... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::rc::Rc;
use crate::{
DesktopContext, <|fim_suffix|> mut handler: impl FnMut(&tray_icon::TrayIconEvent) + 'static,
) -> WryEventHandler {
use_wry_event_handler(move |event, _| {
if let Event::UserEvent(UserWindowEvent::TrayIconEvent(event)) = event {
handler(event);... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use serde::{Deserialize, Serialize};
use tao::window::WindowId;
#[non_exhau<|fim_suffix|>the virtualdom
Poll(WindowId),
/// Handle an ipc message eminating from the window.postMessage of a given webview
Ipc {
id: WindowId,
msg: IpcMessage,
},
/// Handle a hotreload e... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(re... | fim | DioxusLabs/dioxus | javascript |
<|fim_prefix|>use crate::Config;
use crate::{
app::App,
ipc::{IpcMethod, UserWindowEvent},
};
use dioxus_core::*;
use dioxus_document::eval;
use std::any::Any;
use tao::event::{Event, StartCause, WindowEvent};
/// Launch the WebView and run the event loop, with configuration and root props.
///
/// This will b... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![doc = include_str!("readme.md")]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(unexpected_cfgs)]
mod android_sync_lock;
mo... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use tao::window::Window;
#[cfg(not(any(target_os = "ios", target_os = "android")))]
pub type DioxusMenu = muda::Menu;
#[cfg(any(target_os = "ios", target_os = "android"))]
pub type DioxusMenu = ();
#[cfg(not(any(target_os = "ios", target_os = "android")))]
pub type DioxusMenuIcon = muda::Icon;
#[cfg(any... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>-apps/tao/issues/1220). Many android-aware crates —
// including parts of wry itself — call `ndk_context::android_context()` and panic if
// it's uninitialized, which then poisons wry's static mutexes and turns the original
// panic into a confusing `PoisonError` at the next JNI callback. Init... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>tkeyError> {
Ok(())
}
pub fn unregister_all(&self, _: &[HotKey]) -> Result<(), HotkeyError> {
Ok(())
}
}
use std::{error, fmt};
/// An error whose cause the `ShortcutManager` to fail.
#[non_exhaustive]
#[derive(Debug)]
pub enum HotkeyError {
AcceleratorAlreadyRegistered(... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::path::PathBuf;
use crate::{assets::*, webview::WebviewEdits};
use crate::{document::NATIVE_EVAL_JS, file_upload::FileDialogRequest};
use base64::prelude::BASE64_STANDARD;
use dioxus_core::AnyhowContext;
use dioxus_html::{SerializedFileData, SerializedFormObject};
use dioxus_interpreter_js::NATIV... | fim | DioxusLabs/dioxus | rust |
use crate::{DesktopContext, WeakDesktopContext};
use futures_util::{FutureExt, StreamExt};
use generational_box::Owner;
use serde::{Deserialize, de::DeserializeOwned};
use serde_json::Value;
use slab::Slab;
use std::{cell::RefCell, rc::Rc};
use thiserror::Error;
/// Tracks what query ids are currently active
pub(crate... | fim | DioxusLabs/dioxus | rust |
#[cfg(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
pub use global_hotkey::{
Error as HotkeyError, GlobalHotKeyEvent, GlobalHotKeyManager, HotKeyState,
hotkey::{Cod... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> }
}
/// Provides a hook to the tray icon
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
pub fn use_tray_icon() -> Option<tray_icon::TrayIcon> {
use_hook(try_consume_context)
}
<|fim_prefix|>//! tray icon
use dioxus_core::{provide_context, try_consume_context, use_hook}... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>import {
Channel,
DioxusCh<|fim_suffix|>inalizationRegistry ||
new FinalizationRegistry(({ id }) => {
// @ts-ignore - wry gives us this
window.ipc.postMessage(
JSON.stringify({
method: "query",
params: new QueryParams(id, "drop"),
})
);
});
// Get a query f... | fim | DioxusLabs/dioxus | typescript |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.