text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_suffix|> other: 20,
};
assert_eq!(route_without_query.to_string(), "/?other=20");
let parsed_route_without_query = "/?other=20".parse::<Route>().unwrap();
assert_eq!(parsed_route_without_query, route_without_query);
let route_without_query_and_other = Route::Index {
query: None,
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
#[test]
fn with_class() {
#[derive(Routable, Clone, PartialEq, Debug)]
enum ChildRoute {
#[route("/")]
ChildRoot {},
#[route("/:not_static")]
NotStatic { not_static: String },
}
#[derive(Routable, Clone, PartialEq, Debug)]
enum ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(unused)]
use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_history::{History, MemoryHistory};
use dioxus_router::components::HistoryProvider;
fn prepare(path: impl Into<String>) -> VirtualDom {
let mut vdom = VirtualDom::new_with_props(
App,
AppProps {
path: p... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>a href=\"/child/this-is-a-child-route\">Child Link</a>"
);
assert_eq!(
prepare_at::<Route>("/child"),
"<h1>App</h1><a href=\"/test\">Parent Link</a><a href=\"/child/this-is-a-child-route\">Child Link 1</a><a href=\"/child/this-is-a-child-route\">Child Link 2</a>"
);
}
#[test]... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>;
<|fim_prefix|>mod child_outlet;
mod link;
mod navigation;
mod outlet;
mod redirect;
mod witho<|fim_middle|>ut_index<|endoftext|> | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> {
Router::<Route> {}
}
}
// Turn off rustfmt since we're doing layouts and routes in the same enum
#[derive(Routable, Clone, Debug, PartialEq)]
#[rustfmt::skip]
enum Route {
// Wrap Home in a Navbar Layout
#[layout(NavBar)]
// The default route is always "/" unless otherwise ... | fim | DioxusLabs/dioxus | rust |
#![allow(unused)]
use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_history::{History, MemoryHistory};
use dioxus_router::components::HistoryProvider;
fn prepare(path: impl Into<String>) -> VirtualDom {
let mut vdom = VirtualDom::new_with_props(
App,
AppProps {
path: path.into().par... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
use dioxus_history::{History, MemoryHistory};
use dioxus_router::components::HistoryProvider;
use std::{rc::Rc, str::FromStr};
// <|fim_suffix|>ring()
}
);
let mut vdom = VirtualDom::new_with_props(App, AppProps { path });
vdom.rebuild_in_place();
let as_st... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_history::{History, MemoryHistory};
use dioxus_router::components::HistoryProvider;
// Te<|fim_suffix|>HistoryProvider {
history: move |_| Rc::new(MemoryHistory::with_initial_path(path)) as Rc<dyn History>,
Router::<Route> {}
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>&hash_ident);
let ty = if let Some((_, ty)) = field {
ty.clone()
} else {
return Err(syn::Error::new(
route_span,
format!("Could not find a field with the name '{}'", hash_ident),
));
};
Ok(Self {
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2::TokenStream;
use quote::quote;
use syn::Path;
use crate::nest::{Nest, NestId};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LayoutId(pub usize);
#[derive(Debug)]
pub struct Layout {
pub comp: Path,
pub active_nests: Vec<NestId>,
}
impl Layout {
pub fn rout... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
extern crate proc_macro;
use layout::Layout;
use nest::{Nest, NestId};
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::{ToTokens, form... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> ),
));
}
}
Ok(Self {
route: route.value(),
segments: route_segments,
index,
})
}
}
impl Nest {
pub fn dynamic_segments(&self) -> impl Iterator<Item = TokenStream> + '_ {
self.dynamic_segments_name... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use quote::quote;
use syn::{Ident, Type};
use proc_macro2::TokenStream as TokenStream2;
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum QuerySegment {
Single(FullQuerySegment),
Segments(Vec<QueryArgument>),
}
impl QuerySegment {
pub fn contains_ident(&self, ident: &Ident) -> ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use syn::LitStr;
use crate::{
hash::HashFragment,
nest::NestId,
query::QuerySegment,
segment::{RouteSegment, create_error_type, parse_route_segments},
};
#[derive(Debug)]
pub(crate) struct Redirect {
pub route: ... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use quote::{format_ident, quote, quote_spanned};
use syn::Field;
use syn::Path;
use syn::Type;
use syn::parse::Parse;
use syn::parse::ParseStream;
use syn::parse_quote;
use syn::{Ident, LitStr};
use proc_macro2::TokenStream as TokenStream2;
use crate::hash::HashFragment;
use crate::layout::Layout;
use c... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2::TokenStream;
use quote::quote;
use slab::Slab;
use syn::Ident;
use crate::{
RouteEndpoint,
nest::{Nest, NestId},
redirect::Redirect,
route::{Route, RouteType},
segment::{RouteSegment, static_segment_idx},
};
#[derive(Debug, Clone, Default)]
pub(crate) struct ParseRou... | fim | DioxusLabs/dioxus | rust |
use quote::{ToTokens, format_ident, quote};
use syn::{Ident, Type};
use proc_macro2::{Span, TokenStream as TokenStream2};
use crate::{hash::HashFragment, query::QuerySegment};
#[derive(Debug, Clone)]
pub enum RouteSegment {
Static(String),
Dynamic(Ident, Type),
CatchAll(Ident, Type),
}
impl RouteSegment... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::attribute::Attribute;
use crate::{
AttributeValue, BodyNode, HotLiteral, HotReloadFormattedSegment, Segment, TemplateBody,
};
/// A visitor that assigns dynamic ids to nodes and attributes and acc<|fim_suffix|>f !property.name.is_likely_key() {
component.compone... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>eak
None => {
expression.extend(quote! { { ::std::string::String::new() } });
break;
}
_ => {
return non_string_diagnostic(current_if_value.else_value.span());
}
}
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Parse components into the VNode::Component variant
//!
//! Uses the regular robust RsxBlock parser and then validates the component, emitting errors as
//! diagnostics. This was refactored from a straightforward parser to this validation approach so
//! that we can emit errors as diagnostics instead o... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2_diagnostics::Diagnostic;
use quote::ToTokens;
/// A collection of diagnostics
///<|fim_suffix|>ens.extend(diagnostic.clone().emit_as_expr_tokens());
}
}
}
// TODO: Ideally this would be integrated into the existing diagnostics struct, but currently all fields are public so ad... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>tag_name(&self) -> TokenStream2 {
match self {
ElementName::Ident(i) => quote! { dioxus_elements::elements::#i::TAG_NAME },
ElementName::Custom(s) => quote! { #s },
}
}
pub fn span(&self) -> Span {
match self {
ElementName::Ident(i) => i... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{DynIdx, PartialExpr};
use quote::{ToTokens, TokenStreamExt, quote};
use syn::parse::Parse;
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ExprNode {
pub expr: PartialExpr,
pub dyn_idx: DynIdx,
}
impl ExprNode {
pub fn span(&self) -> proc_macro2::Span {
self.expr.span()... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use super::*;
use location::DynIdx;
use proc_macro2::TokenStream as TokenStream2;
use syn::{Expr, Pat, braced, token::Brace};
#[non_exhaustive]
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ForLoop {
pub for_token: Token![for],
pub pat: Pat,
pub in_token: Token![in],
pub expr: Box<Exp... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> } else if let Some(else_branch) = else_branch {
body.append_all(quote! {
else {
{#else_branch}
}
});
terminated = true;
break;
} else {
eli... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2::{Span, TokenStream};
use quote::{ToTokens, TokenStreamExt, quote, quote_spanned};
use std::collections::HashMap;
use syn::{
parse::{Parse, ParseStream},
*,
};
/// A hot-reloadable formatted string, boolean, number or other literal
///
/// This wraps LitStr with some extra goodies... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> call, with `RsxRender` being the primary entrance into parsing.
//! This feature must support:
//! - [x] Optionally rendering if the `in XYZ` pattern is present
//! - [x] Fragments as top-level element (through ambiguous)
//! - [x] Components as top-level element (through ambiguous)
//! - [x] Tags as top... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use proc_macro2::Span;
use quote::ToTokens;
use quote::quote;
use std::fmt<|fim_suffix|>
Segment::Formatted(_fmt) => {
// increment idx for the dynamic segment so we maintain the mapping
let _idx = self.dynamic_node_indexes[idx].get();
idx += 1;
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>her DynIdx.
#[derive(Clone, Debug, Default)]
pub struct DynIdx {
idx: Cell<Option<usize>>,
}
impl PartialEq for DynIdx {
fn eq(&self, _other: &Self) -> bool {
true
}
}
impl Eq for DynIdx {}
impl DynIdx {
pub fn set(&self, idx: usize) {
self.idx.set(Some(idx));
}
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> }
}
pub fn is_litstr(&self) -> bool {
matches!(self, BodyNode::Text { .. })
}
pub fn span(&self) -> Span {
match self {
BodyNode::Element(el) => el.name.span(),
BodyNode::Component(component) => component.name.span(),
BodyNode::Text(... | fim | DioxusLabs/dioxus | rust |
use crate::PartialExpr;
use proc_macro2::TokenStream;
use quote::ToTokens;
use std::hash::{Hash, Hasher};
use syn::{
Attribute, Expr, Pat, PatType, Result, ReturnType, Token, Type,
parse::{Parse, ParseStream},
punctuated::Punctuated,
};
use syn::{BoundLifetimes, ExprClosure};
/// A closure whose body might... | fim | DioxusLabs/dioxus | rust |
use proc_macro2::{Delimiter, TokenStream as TokenStream2, TokenTree};
use quote::ToTokens;
use std::hash;
use syn::{Expr, parse::Parse, spanned::Spanned, token::Brace};
/// A raw expression potentially wrapped in curly braces that is parsed from the input stream.
///
/// If there are no braces, it tries to parse as an... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>t = quote::quote! {
{
some::cool::Component
}
};
let _parsed: RsxBlock = syn::parse2(input).unwrap();
}
#[test]
fn incomplete_root_elements() {
use syn::parse::Parser;
let input = quote::quote! {
di
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>set(self.next_template_idx());
self.cascade_hotreload_info(&comp.children.roots);
}
BodyNode::ForLoop(floop) => {
floop.body.template_idx.set(self.next_template_idx());
self.cascade_hotreload_info(&floop.body.root... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>::Template::new(
__TEMPLATE_ROOTS,
&[ #( #node_paths ),* ],
&[ #( #attr_paths ),* ],
);
// NOTE: Allocating a temporary is important to make reads within rsx drop before the value is returned
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>urce.to_token_stream());
assert_eq!(input.input.source.value(), "hello world");
}
}
<|fim_prefix|>use crate::{HotReloadFormattedSegment, IfmtInput, literal::HotLiteral, location::DynIdx};
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::ToTokens;
use quote::{TokenStreamExt, quo... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>.span()))
}
<|fim_prefix|>#![allow(unused)]
use proc_macro2::TokenStream as TokenStream2;
use std::{fmt::Debug, hash::Hash};
use syn::{
Ident,
ext::IdentExt,
parse::{Parse, ParseBuffer},
};
/// Parse a raw ident and return a new ident with the r# prefix added
pub fn parse_raw_ident(parse_buf... | fim | DioxusLabs/dioxus | rust |
use dioxus_rsx::CallBody;
use quote::ToTokens;
use prettier_please::PrettyUnparse;
#[test]
fn callbody_ctx() {
let item = quote::quote! {
div {
h1 {
id: "Some cool attribute {cool}"
}
for item in items {
"Something {cool}"
}
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Compare two files and find any rsx calls that have changed
//!
//! This is used to determine if a hotreload is needed.
//! We use a special syn visitor to find all the rsx! calls in the file and then compare them to see
//! if they are the same. This visitor will actually remove the rsx! calls and rep... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>h
match (&new_field.value, &old_field.value) {
// If the values are both literals, we can try to hotreload them
(
AttributeValue::AttrLiteral(new_value),
AttributeValue::AttrLiteral(old_value),
) => {
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ode {
BodyNode::Element(el) => {
let rust_name = el.name.to_string();
let (tag, namespace) =
Ctx::map_element(&rust_name).unwrap_or((intern(rust_name.as_str()), None));
TemplateNode::Element {
tag,
namespace,
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> });
} // If it is a dynamic segment, we need to check if it exists in the formatted segments pool
Segment::Formatted(formatted) => {
let index = self.dynamic_text_segments.position(|s| s == formatted)?;
segments.push(FmtS... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>sions;
<|fim_prefix|>mod collect;
pub use collect::*;
mod dif<|fim_middle|>f;
pub use diff::*;
mod last_build_state;
mod exten<|endoftext|> | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Adversarial tests for rsx-hotreload.
//!
//! These tests probe edge cases around ordering, indexing, and pool matching
//! where the hotreload algorithm is likely to produce wrong outputs.
#![allow(unused)]
use std::collections::HashMap;
use dioxus_core::{
Template, TemplateAttribute, TemplateN... | fim | DioxusLabs/dioxus | rust |
#![allow(unused)]
use std::collections::HashMap;
use dioxus_core::{
Template, TemplateAttribute, TemplateNode, VNode,
internal::{
FmtSegment, FmtedSegments, HotReloadAttributeValue, HotReloadDynamicAttribute,
HotReloadDynamicNode, HotReloadLiteral, HotReloadedTemplate, NamedAttribute,
},
}... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus_rsx_hotreload::diff_rsx;
use syn::File;
macro_rules! assert_rsx_changed {
(
$( #[doc = $doc:expr] )*
$name:ide<|fim_suffix|>(old: &str, new: &str) -> (File, File) {
let old = syn::parse_file(old).unwrap();
let new = syn::parse_file(new).unwrap();
(old, new)
}
a... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use html_parser::Dom;
fn main() {
let html = r#"
<div>
<div class="asd">hello world!</div>
<div id="asd">hello world!</div>
<div id="asd">hello world!</div>
<div for="asd">hello world!</div>
<div async="asd">hello world!</div>
<div LargeThing="asd">... | 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")]
use convert_case::{Case, Casing};
use dioxus_html::{map_html_attribute_to_rsx, map_html_element_to_rsx};
use di... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use html_parser::Dom;
// Regression test for https://github.com/DioxusLabs/dioxus<|fim_suffix|>><div>⌛⌛⌛⌛</div>"#.trim();
let dom = Dom::parse(html).unwrap();
let body = dioxus_rsx_rosetta::rsx_from_html(&dom);
let out = dioxus_autofmt::write_block_out(&bo... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>dioxus_autofmt::write_block_out(&body).unwrap();
let expected = r#"
div {
h1 { "hello world!" }
h2 { "hello world!" }
h3 { "hello world!" }
h4 { "hello world!" }
h5 { "hello world!" }
h6 { "hello world!" }
}"#;
pretty_assertions::assert_eq!(... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>sd", "hello world!" }
}"#;
pretty_assertions::assert_eq!(&out, &expected);
}
<|fim_prefix|>use html_parser::Dom;
#[test]
fn raw_attribute() {
l<|fim_middle|>et html = r#"
<div>
<div unrecognizedattribute="asd">hello world!</div>
</div>
"#
.trim();
let dom = Dom::p... | fim | DioxusLabs/dioxus | rust |
use html_parser::Dom;
#[test]
fn simple_elements() {
let html = r#"
<div>
<div class="asd">hello world!</div>
<div id="asd">hello world!</div>
<div id="asd">hello world!</div>
<div for="asd">hello world!</div>
<div async="asd">hello world!</div>
</div>
"#
.tr... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>00f" }
}"##
);
let html = r###"
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="flag-icons-cn" viewBox="0 0 640 480">
<defs>
<path id="cn-a" fill="#ff0" d="M-.6.8 0-1 .6.8-1-.3h2z"/>
</defs>
<path fill="#ee1c25" d="M0 0h640v480H0z"/>
<use xli... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use html_parser::Dom;
#[test]
fn web_components_translate() {
let html = r#"
<div>
<|fim_suffix|>out = dioxus_autofmt::write_block_out(&body).unwrap();
let expected = r#"
div {
my-component {}
}"#;
pretty_assertions::assert_eq!(&out, &expected);
}
<|fim_middle|> <my... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>up to the parent may cause issues if you read the signal after the child scope is dropped
use_hook(|| counts.push(signal_owned_by_child));
rsx! {
button {
onclick: move |_| signal_owned_by_child += 1,
"{signal_owned_by_child}"
}
}
}
<|fim_prefix|>#[comp... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>
"{counts:?}"
// Instead of passing up a signal, we can just write to the signal that lives in the parent
for index in 0..counts.len() {
Counter {
index,
counts
}
}
}
}
#[component]
fn Counter(index: usize, mut co... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(non_snake_cas<|fim_suffix|>the signal, so when the signal changes it will rerun
#[component]
fn Child() -> Element {
let signal: Signal<i32> = use_context();
rsx! { "{signal}" }
}
<|fim_middle|>e)]
use dioxus::prelude::*;
fn main() {
dioxus::launch(app)
}
// Because signal is never... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
let mut signal = use_signal(|| 0);
use_future(move || async move {
loop {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
signal += 1;
}
});
rsx! {
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(non_snake_case)]
use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
let mut vec = use_signal(|| vec![0]);
rsx! {
button {
oncl<|fim_suffix|> button {
onclick: move |_| {
vec.write().pop();
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>//! Signals can degrade into a Read variant automatically
//! This is done thanks to<|fim_suffix|>-> Element {
rsx! {
div { "Count: {count}" }
{children}
}
}
<|fim_middle|> a conversion by the #[component] macro
use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn a... | fim | DioxusLabs/dioxus | rust |
use dioxus::prelude::*;
fn main() {
dioxus::launch(app)
}
fn app() -> Element {
let mut signal = use_signal(|| 0);
let doubled = use_memo(move || signal * 2);
rsx! {
button {
onclick: move |_| signal += 1,
"Increase"
}
Child { signal: doubled }
}
}
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>::sleep(std::time::Duration::from_secs(1));
signal += 1;
}
});
});
rsx! {
button { onclick: move |_| signal += 1, "Increase" }
"{signal}"
}
}
<|fim_prefix|>use dioxus::pre<|fim_middle|>lude::*;
fn main() {
dioxus::launch(app);
}
fn app... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>
store += 1;
if store() >= 10 {
break;
}
}
});
});
rsx! {}
}
<|fim_prefix|>use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
let mut store = use_hook(|| Store::new_may... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ln!("running many signals");
let mut data = use_context::<ApplicationData>();
rsx! {
button {
onclick: move |_| data.many_signals.write().push(Signal::new(0)),
"Create"
}
button {
onclick: move |_| { data.many_signals.write().pop(); },
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::{any::Any, ops::Deref};
use dioxus_core::{IntoAttributeValue, IntoDynNode, Subscribers};
use generational_box::{BorrowResult, Storage, SyncStorage, UnsyncStorage};
use crate::{
CopyValue, Global, InitializeFromFunction, MappedMutSignal, MappedSignal, Memo, Readable,
ReadableExt, Readabl... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>#![allow(clippy::unnecessary_operation)]
#![allow(clippy::no_effect)]
use dioxus_core::{Runtime, Subscribers};
use dioxus_core::{ScopeId, current_owner, current_scope_id};
use generational_box::{
AnyStorage, BorrowResult, GenerationalBox, GenerationalBoxId, Storage, UnsyncStorage,
};
use std::ops::De... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use super::{Global, InitializeFromFunction};
use crate::Memo;
use crate::read::ReadableExt;
use crate::read_impls;
impl<T: PartialEq + 'static> InitializeFromFunction<T> for Memo<T> {
fn initialize_from_function(f: fn() -> T) -> Self {
Memo::new(f)
}
}
/// A memo that can be accessed fro... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>2,
index: usize,
) -> Self {
Self {
constructor,
key: GlobalKey::File {
file,
line: line as _,
column: column as _,
index: index as _,
},
phantom: std::marker::PhantomData,
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use super::{Global, InitializeFromFunction};
use crate::Signal;
use crate::read::ReadableExt;
use crate::read_impls;
impl<T: 'static> InitializeFromFunction<T> for Signal<T> {
fn<|fim_suffix|> /// Resolve the global signal. This will try to get the existing value from the current virtual dom, and i... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> where
$($extra_bound_ty: $extra_bound,)*
)?
{
#[track_caller]
fn mul_assign(&mut self, rhs: T) {
self.with_mut(|v| *v = *v * rhs)
}
}
impl<T: std::ops::Mul<Output = T> + Copy + 'static
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ncStorage,
};
mod read;
pub use read::*;
mod write;
pub use write::*;
mod props;
pub use props::*;
pub mod warnings;
mod boxed;
pub use boxed::*;
/// A macro to define extension methods for signal types that call the method with either `with` or `with_mut` depending on the mutability of self.
macro_... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{ReadableExt, ReadableRef, read::Readable, read_impls};
use dioxus_core::{IntoAttributeValue, Subscribers};
use generational_box::{AnyStorage, BorrowResult};
use std::ops::Deref;
/// A read only signal that has been mapped to a new type.
pub struct MappedSignal<O: ?Sized, V, F = fn(&<V as Read... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::ops::Deref;
use crate::{
Readable, ReadableExt, ReadableRef, Writable, WritableExt, WritableRef, WriteLock, read_impls,
write_impls,
};
use dioxus_core::{IntoAttributeValue, Subscribers};
use generational_box::{AnyStorage, BorrowResult};
/// A read only signal that has been mapped to a ... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>lick: move |_| *SIGNAL.write() += 1,
/// "{DOUBLED}"
/// }
/// }
/// }
/// ```
///
/// <div class="warning">
///
/// Global memos are generally not recommended for use in libraries because it makes it more difficult to allow multiple instances of... | fim | DioxusLabs/dioxus | rust |
use crate::{ReadSignal, Signal};
use dioxus_core::SuperFrom;
#[doc(hidden)]
pub struct ReadFromMarker<M>(std::marker::PhantomData<M>);
impl<T, O, M> SuperFrom<T, ReadFromMarker<M>> for ReadSignal<O>
where
O: SuperFrom<T, M> + 'static,
T: 'static,
{
fn super_from(input: T) -> Self {
ReadSignal::new... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>an error"))
.clone()
}
/// Attempts to read the inner value of the Option.
#[track_caller]
fn as_ref(&self) -> Result<ReadableRef<'_, Self, T>, ReadableRef<'_, Self, E>>
where
T: 'static,
E: 'static,
{
let read = self.read();
match read.... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> loop {
// Recompute the value
rc.reset_and_run_in(&mut recompute);
// Wait for context to change
let _ = changed.next().await;
}
});
SetCompare { subscribers }
}
}
impl<R: Eq + Hash + 'static> SetCompare... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use crate::{
CopyValue, Global, GlobalMemo, GlobalSignal, Memo, ReadableRef, WritableRef, default_impl,
fmt_impls, read::*, write::*, write_impls,
};
use dioxus_core::{IntoAttributeValue, IntoDynNode, ReactiveContext, ScopeId, Subscribers};
use generational_box::{BorrowResult, Storage, SyncStorage... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>reated in. If you use the value in a scope that may be dropped after the origin scope,
it is very easy to use the value after it has been dropped. To fix this, you can move the value to the parent of all of the scopes that it is used in.
Broken example ❌:
```rust
{broken_example}
```
Fixed example ✅:
``... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>{
WriteSignal::new(self)
}
}
impl<T: Writable<Storage = UnsyncStorage> + 'static> WritableBoxedExt for T {
fn boxed_mut(self) -> WriteSignal<Self::Target> {
WriteSignal::new(self)
}
}
/// An extension trait for [`Writable<Option<T>>`]` that provides some convenience methods.
... | fim | DioxusLabs/dioxus | rust |
#![allow(unused, non_upper_case_globals, non_snake_case)]
use dioxus::prelude::*;
use dioxus_core::{ElementId, Mutation, NoOpMutations, generation};
use dioxus_signals::*;
#[test]
fn create_signals_global() {
let mut dom = VirtualDom::new(|| {
rsx! {
for _ in 0..10 {
Child {}
... | fim | DioxusLabs/dioxus | rust |
#![allow(unused, non_upper_case_globals, non_snake_case)]
use dioxus::html::p;
use dioxus::prelude::*;
use dioxus_core::{ElementId, generation};
use dioxus_core::{NoOpMutations, ScopeState};
use dioxus_signals::*;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::atomic::{AtomicBool... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>_count, &2);
}
}
}
<|fim_prefix|>#![allow(unused, non_upper_case_globals, non_snake_case)]
use dioxus_core::{NoOpMutations, current_scope_id, generation};
use std::collections::HashMap;
use std::rc::Rc;
use dioxus::prelude::*;
use dioxus_core::ElementId;
use dioxus_signals::*;
use std::cell:... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>input"
| "link"
| "meta"
| "param"
| "source"
| "track"
| "wbr"
)
}
<|fim_prefix|>//! Dioxus SSR uses the design of templates to cache as much as possible about the HTML a block of rsx can render.
//!
//! The structure of template... | 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")]
mod cache;
pub mod config;
pub mod renderer;
pub mod template;
use dioxus_core::{Element, VirtualDom};
pub us... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use super::cache::Segment;
use crate::cache::StringCache;
use dioxus_core::{
Attribute, AttributeValue, DynamicNode, Element, ScopeId, Template, VNode, VirtualDom,
};
use rustc_hash::FxHashMap;
use std::fmt::Write;
use std::sync::Arc;
type ComponentRenderCallback = Arc<
dyn Fn(&mut Renderer, &mu... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
#[test]
fn static_boolean_attributes() {
fn app() -> Element {
rsx! {
div { hidden: "false" }
div { hidden: "true" }
}
}
let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>yle>"
);
}
#[test]
fn escape_static_component_fragment_div() {
#[component]
fn StyleContents() -> Element {
rsx! { "body {{ font-family: \"sans-serif\"; }}" }
}
fn app() -> Element {
rsx! {
div {
StyleContents {}
}
}
... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use dioxus::prelude::*;
// Regression test for https://github.com/DioxusLabs/dioxus/issues/3844
#[test]
fn forward_spreads() {
#[derive(Props, Clone, PartialEq)]
struct Comp1Props {
#[props(extends = GlobalAttributes)]
attributes: Vec<Attribute>,
}
#[component]
fn Com... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>(app2);
dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(
dioxus_ssr::pre_render(&dom),
r#"<div data-node-hydration="0"><!--node-id1-->hello<!--#--></div>"#
);
fn app3() -> Element {
rsx! { Child3 {} }
}
fn Child3() -> Element {
rsx! { div... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|> rsx! { div { dangerous_inner_html: "{inner_html}" } }
}
let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(dioxus_ssr::render(&dom), r#"<div><div>1234</div></div>"#);
}
<|fim_prefix|>us<|fim_middle|>e dioxus::prelude::*;
#[test]
fn static_inn... | fim | DioxusLabs/dioxus | rust |
#![allow(non_snake_case)]
use dioxus::prelude::*;
#[test]
fn simple() {
fn App() -> Element {
rsx! { div { "hello!" } }
}
let mut dom = VirtualDom::new(App);
dom.rebuild(&mut dioxus_core::NoOpMutations);
assert_eq!(dioxus_ssr::render(&dom), "<div>hello!</div>");
assert_eq!(
... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ibute>,
extra_data: String,
extra_data2: String,
}
#[component]
fn SpreadableComponent(props: Props) -> Element {
rsx! {
audio { ..props.attributes, "1: {props.extra_data}\n2: {props.extra_data2}" }
}
}
<|fim_prefix|>use dioxus::prelude::*;
#[test]
fn spread() {
let dom = V... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>
}
#[test]
fn partially_dynamic_styles() {
let dynamic = 123;
assert_eq!(
dioxus_ssr::render_element(rsx! {
div { width: "100px", height: "{dynamic}px" }
}),
r#"<div style="width:100px;height:123px;"></div>"#
);
}
#[test]
fn dynamic_styles() {
let dyn... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>en(), 2);
/// store.clear();
/// assert!(store.is_empty());
/// ```
pub fn clear(&mut self)
where
Lens: Writable,
{
self.selector().mark_dirty_shallow();
self.selector().write_untracked().clear();
}
/// Retain only the key-value pairs that satisfy t... | fim | DioxusLabs/dioxus | rust |
<|fim_prefix|>use std::ops::DerefMut;
use crate::{MappedStore, store::Store};
use dioxus_signals::Re<|fim_suffix|>lue| value.deref();
let map_mut: fn(&mut T) -> &mut T::Target = |value| value.deref_mut();
self.into_selector().map(map, map_mut).into()
}
}
<|fim_middle|>adable;
impl<Lens, T> Store<T... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>ed(key.borrow())
.mark_dirty();
self.selector().write_untracked().insert(key, value);
}
/// Remove a key-value pair from the HashMap. This method will mark the store as shallowly dirty, causing
/// re-runs of any reactive scopes that depend on the shape of the map or the v... | fim | DioxusLabs/dioxus | rust |
//! Additional utilities for indexing into stores.
use std::{
collections::{BTreeMap, HashMap},
hash::Hash,
ops::{self, Index, IndexMut},
};
use crate::{ReadStore, scope::SelectorScope, store::Store};
use dioxus_signals::{
AnyStorage, BorrowError, BorrowMutError, ReadSignal, Readable, UnsyncStorage, W... | fim | DioxusLabs/dioxus | rust |
<|fim_suffix|>b mod index;
mod option;
mod result;
pub mod slice;
mod vec;
<|fim_prefix|>pub mod btreemap;
mod deref;
pub mod<|fim_middle|> hashmap;
pu<|endoftext|> | fim | DioxusLabs/dioxus | rust |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.