mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-28 10:11:56 -05:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a398648b50 | ||
|
|
eef1f2e89d |
2
.github/workflows/ci-semver.yml
vendored
2
.github/workflows/ci-semver.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
uses: ./.github/workflows/get-leptos-changed.yml
|
||||
test:
|
||||
needs: [get-leptos-changed]
|
||||
if: needs.get-leptos-changed.outputs.leptos_changed == 'true' && github.event.pull_request.labels[0].name != 'breaking'
|
||||
if: github.event.pull_request.labels[0].name == 'semver' # needs.get-leptos-changed.outputs.leptos_changed == 'true' && github.event.pull_request.labels[0].name != 'breaking'
|
||||
name: Run semver check (nightly-2024-08-01)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
555
Cargo.lock
generated
555
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
31
Cargo.toml
31
Cargo.toml
@@ -40,7 +40,7 @@ members = [
|
||||
exclude = ["benchmarks", "examples", "projects"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.76"
|
||||
|
||||
@@ -50,25 +50,25 @@ any_spawner = { path = "./any_spawner/", version = "0.2.0" }
|
||||
const_str_slice_concat = { path = "./const_str_slice_concat", version = "0.1.0" }
|
||||
either_of = { path = "./either_of/", version = "0.1.0" }
|
||||
hydration_context = { path = "./hydration_context", version = "0.2.0" }
|
||||
leptos = { path = "./leptos", version = "0.7.1" }
|
||||
leptos_config = { path = "./leptos_config", version = "0.7.1" }
|
||||
leptos_dom = { path = "./leptos_dom", version = "0.7.1" }
|
||||
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.7.1" }
|
||||
leptos_integration_utils = { path = "./integrations/utils", version = "0.7.1" }
|
||||
leptos_macro = { path = "./leptos_macro", version = "0.7.1" }
|
||||
leptos_router = { path = "./router", version = "0.7.1" }
|
||||
leptos_router_macro = { path = "./router_macro", version = "0.7.1" }
|
||||
leptos_server = { path = "./leptos_server", version = "0.7.1" }
|
||||
leptos_meta = { path = "./meta", version = "0.7.1" }
|
||||
leptos = { path = "./leptos", version = "0.7.0" }
|
||||
leptos_config = { path = "./leptos_config", version = "0.7.0" }
|
||||
leptos_dom = { path = "./leptos_dom", version = "0.7.0" }
|
||||
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.7.0" }
|
||||
leptos_integration_utils = { path = "./integrations/utils", version = "0.7.0" }
|
||||
leptos_macro = { path = "./leptos_macro", version = "0.7.0" }
|
||||
leptos_router = { path = "./router", version = "0.7.0" }
|
||||
leptos_router_macro = { path = "./router_macro", version = "0.7.0" }
|
||||
leptos_server = { path = "./leptos_server", version = "0.7.0" }
|
||||
leptos_meta = { path = "./meta", version = "0.7.0" }
|
||||
next_tuple = { path = "./next_tuple", version = "0.1.0" }
|
||||
oco_ref = { path = "./oco", version = "0.2.0" }
|
||||
or_poisoned = { path = "./or_poisoned", version = "0.1.0" }
|
||||
reactive_graph = { path = "./reactive_graph", version = "0.1.0" }
|
||||
reactive_stores = { path = "./reactive_stores", version = "0.1.0" }
|
||||
reactive_stores_macro = { path = "./reactive_stores_macro", version = "0.1.0" }
|
||||
server_fn = { path = "./server_fn", version = "0.7.1" }
|
||||
server_fn_macro = { path = "./server_fn_macro", version = "0.7.1" }
|
||||
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.7.1" }
|
||||
server_fn = { path = "./server_fn", version = "0.7.0" }
|
||||
server_fn_macro = { path = "./server_fn_macro", version = "0.7.0" }
|
||||
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.7.0" }
|
||||
tachys = { path = "./tachys", version = "0.1.0" }
|
||||
|
||||
[profile.release]
|
||||
@@ -78,6 +78,3 @@ opt-level = 'z'
|
||||
|
||||
[workspace.metadata.cargo-all-features]
|
||||
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]
|
||||
|
||||
[workspace.lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)', 'cfg(erase_components)'] }
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "any_spawner"
|
||||
version = "0.2.1"
|
||||
version = "0.2.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "either_of"
|
||||
version = "0.1.2"
|
||||
version = "0.1.1"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -134,7 +134,7 @@ tuples!(EitherOf14 + EitherOf14Future + EitherOf14FutureProj => A, B, C, D, E, F
|
||||
tuples!(EitherOf15 + EitherOf15Future + EitherOf15FutureProj => A, B, C, D, E, F, G, H, I, J, K, L, M, N, O);
|
||||
tuples!(EitherOf16 + EitherOf16Future + EitherOf16FutureProj => A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P);
|
||||
|
||||
/// Matches over the first expression and returns an either ([`Either`], [`EitherOf3`], ... [`EitherOf8`])
|
||||
/// Matches over the first expression and returns an either ([`Either`], [`EitherOf3`], ... [`EitherOf6`])
|
||||
/// composed of the values returned by the match arms.
|
||||
///
|
||||
/// The pattern syntax is exactly the same as found in a match arm.
|
||||
@@ -197,29 +197,6 @@ macro_rules! either {
|
||||
$e_pattern => $crate::EitherOf6::E($e_expression),
|
||||
$f_pattern => $crate::EitherOf6::F($f_expression),
|
||||
}
|
||||
};
|
||||
($match:expr, $a_pattern:pat => $a_expression:expr, $b_pattern:pat => $b_expression:expr, $c_pattern:pat => $c_expression:expr, $d_pattern:pat => $d_expression:expr, $e_pattern:pat => $e_expression:expr, $f_pattern:pat => $f_expression:expr, $g_pattern:pat => $g_expression:expr,) => {
|
||||
match $match {
|
||||
$a_pattern => $crate::EitherOf7::A($a_expression),
|
||||
$b_pattern => $crate::EitherOf7::B($b_expression),
|
||||
$c_pattern => $crate::EitherOf7::C($c_expression),
|
||||
$d_pattern => $crate::EitherOf7::D($d_expression),
|
||||
$e_pattern => $crate::EitherOf7::E($e_expression),
|
||||
$f_pattern => $crate::EitherOf7::F($f_expression),
|
||||
$g_pattern => $crate::EitherOf7::G($g_expression),
|
||||
}
|
||||
};
|
||||
($match:expr, $a_pattern:pat => $a_expression:expr, $b_pattern:pat => $b_expression:expr, $c_pattern:pat => $c_expression:expr, $d_pattern:pat => $d_expression:expr, $e_pattern:pat => $e_expression:expr, $f_pattern:pat => $f_expression:expr, $g_pattern:pat => $g_expression:expr, $h_pattern:pat => $h_expression:expr,) => {
|
||||
match $match {
|
||||
$a_pattern => $crate::EitherOf8::A($a_expression),
|
||||
$b_pattern => $crate::EitherOf8::B($b_expression),
|
||||
$c_pattern => $crate::EitherOf8::C($c_expression),
|
||||
$d_pattern => $crate::EitherOf8::D($d_expression),
|
||||
$e_pattern => $crate::EitherOf8::E($e_expression),
|
||||
$f_pattern => $crate::EitherOf8::F($f_expression),
|
||||
$g_pattern => $crate::EitherOf8::G($g_expression),
|
||||
$h_pattern => $crate::EitherOf8::H($h_expression),
|
||||
}
|
||||
}; // if you need more eithers feel free to open a PR ;-)
|
||||
}
|
||||
|
||||
@@ -256,23 +233,4 @@ fn either_macro() {
|
||||
16 => 24u8,
|
||||
_ => 12,
|
||||
);
|
||||
let _: EitherOf7<&str, f64, char, f32, u8, i8, i32> = either!(12,
|
||||
12 => "12",
|
||||
13 => 0.0,
|
||||
14 => ' ',
|
||||
15 => 0.0f32,
|
||||
16 => 24u8,
|
||||
17 => 2i8,
|
||||
_ => 12,
|
||||
);
|
||||
let _: EitherOf8<&str, f64, char, f32, u8, i8, u32, i32> = either!(12,
|
||||
12 => "12",
|
||||
13 => 0.0,
|
||||
14 => ' ',
|
||||
15 => 0.0f32,
|
||||
16 => 24u8,
|
||||
17 => 2i8,
|
||||
18 => 42u32,
|
||||
_ => 12,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "hydration_context"
|
||||
version = "0.2.1"
|
||||
version = "0.2.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
@@ -25,6 +25,3 @@ browser = ["dep:wasm-bindgen", "dep:js-sys"]
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
|
||||
@@ -121,6 +121,3 @@ skip_feature_sets = [
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
@@ -1,150 +0,0 @@
|
||||
use crate::attr::{
|
||||
any_attribute::{AnyAttribute, IntoAnyAttribute},
|
||||
Attribute, NextAttribute,
|
||||
};
|
||||
use leptos::prelude::*;
|
||||
|
||||
/// Function stored to build/rebuild the wrapped children when attributes are added.
|
||||
type ChildBuilder<T> = dyn Fn(AnyAttribute) -> T + Send + Sync + 'static;
|
||||
|
||||
/// Intercepts attributes passed to your component, allowing passing them to any element.
|
||||
///
|
||||
/// By default, Leptos passes any attributes passed to your component (e.g. `<MyComponent
|
||||
/// attr:class="some-class"/>`) to the top-level element in the view returned by your component.
|
||||
/// [`AttributeInterceptor`] allows you to intercept this behavior and pass it onto any element in
|
||||
/// your component instead.
|
||||
///
|
||||
/// Must be the top level element in your component's view.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// Any attributes passed to MyComponent will be passed to the #inner element.
|
||||
///
|
||||
/// ```
|
||||
/// # use leptos::prelude::*;
|
||||
/// use leptos::attribute_interceptor::AttributeInterceptor;
|
||||
///
|
||||
/// #[component]
|
||||
/// pub fn MyComponent() -> impl IntoView {
|
||||
/// view! {
|
||||
/// <AttributeInterceptor let:attrs>
|
||||
/// <div id="wrapper">
|
||||
/// <div id="inner" {..attrs} />
|
||||
/// </div>
|
||||
/// </AttributeInterceptor>
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[component]
|
||||
pub fn AttributeInterceptor<Chil, T>(
|
||||
/// The elements that will be rendered, with the attributes this component received as a
|
||||
/// parameter.
|
||||
children: Chil,
|
||||
) -> impl IntoView
|
||||
where
|
||||
Chil: Fn(AnyAttribute) -> T + Send + Sync + 'static,
|
||||
T: IntoView,
|
||||
{
|
||||
AttributeInterceptorInner::new(children)
|
||||
}
|
||||
|
||||
/// Wrapper to intercept attributes passed to a component so you can apply them to a different
|
||||
/// element.
|
||||
struct AttributeInterceptorInner<T: IntoView, A> {
|
||||
children_builder: Box<ChildBuilder<T>>,
|
||||
children: T,
|
||||
attributes: A,
|
||||
}
|
||||
|
||||
impl<T: IntoView> AttributeInterceptorInner<T, ()> {
|
||||
/// Use this as the returned view from your component to collect the attributes that are passed
|
||||
/// to your component so you can manually handle them.
|
||||
pub fn new<F>(children: F) -> Self
|
||||
where
|
||||
F: Fn(AnyAttribute) -> T + Send + Sync + 'static,
|
||||
{
|
||||
let children_builder = Box::new(children);
|
||||
let children = children_builder(().into_any_attr());
|
||||
|
||||
Self {
|
||||
children_builder,
|
||||
children,
|
||||
attributes: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoView, A: Attribute> Render for AttributeInterceptorInner<T, A> {
|
||||
type State = <T as Render>::State;
|
||||
|
||||
fn build(self) -> Self::State {
|
||||
self.children.build()
|
||||
}
|
||||
|
||||
fn rebuild(self, state: &mut Self::State) {
|
||||
self.children.rebuild(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoView, A> AddAnyAttr for AttributeInterceptorInner<T, A>
|
||||
where
|
||||
A: Attribute,
|
||||
{
|
||||
type Output<SomeNewAttr: leptos::attr::Attribute> =
|
||||
AttributeInterceptorInner<T, <<A as NextAttribute>::Output<SomeNewAttr> as Attribute>::CloneableOwned>;
|
||||
|
||||
fn add_any_attr<NewAttr: leptos::attr::Attribute>(
|
||||
self,
|
||||
attr: NewAttr,
|
||||
) -> Self::Output<NewAttr>
|
||||
where
|
||||
Self::Output<NewAttr>: RenderHtml,
|
||||
{
|
||||
let attributes =
|
||||
self.attributes.add_any_attr(attr).into_cloneable_owned();
|
||||
|
||||
let children =
|
||||
(self.children_builder)(attributes.clone().into_any_attr());
|
||||
|
||||
AttributeInterceptorInner {
|
||||
children_builder: self.children_builder,
|
||||
children,
|
||||
attributes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IntoView, A: Attribute> RenderHtml for AttributeInterceptorInner<T, A> {
|
||||
type AsyncOutput = T::AsyncOutput;
|
||||
|
||||
const MIN_LENGTH: usize = T::MIN_LENGTH;
|
||||
|
||||
fn dry_resolve(&mut self) {
|
||||
self.children.dry_resolve()
|
||||
}
|
||||
|
||||
fn resolve(
|
||||
self,
|
||||
) -> impl std::future::Future<Output = Self::AsyncOutput> + Send {
|
||||
self.children.resolve()
|
||||
}
|
||||
|
||||
fn to_html_with_buf(
|
||||
self,
|
||||
buf: &mut String,
|
||||
position: &mut leptos::tachys::view::Position,
|
||||
escape: bool,
|
||||
mark_branches: bool,
|
||||
) {
|
||||
self.children
|
||||
.to_html_with_buf(buf, position, escape, mark_branches)
|
||||
}
|
||||
|
||||
fn hydrate<const FROM_SERVER: bool>(
|
||||
self,
|
||||
cursor: &leptos::tachys::hydration::Cursor,
|
||||
position: &leptos::tachys::view::PositionState,
|
||||
) -> Self::State {
|
||||
self.children.hydrate::<FROM_SERVER>(cursor, position)
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ type BoxedChildrenFn = Box<dyn Fn() -> AnyView + Send>;
|
||||
/// )
|
||||
/// }
|
||||
pub trait ToChildren<F> {
|
||||
/// Convert the provided type (generally a closure) to Self (generally a "children" type,
|
||||
/// Convert the provided type to (generally a closure) to Self (generally a "children" type,
|
||||
/// e.g., [Children]). See the implementations to see exactly which input types are supported
|
||||
/// and which "children" type they are converted to.
|
||||
fn to_children(f: F) -> Self;
|
||||
@@ -285,13 +285,6 @@ impl<T> Debug for TypedChildrenFn<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for TypedChildrenFn<T> {
|
||||
// Manual implementation to avoid the `T: Clone` bound.
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TypedChildrenFn<T> {
|
||||
/// Extracts the inner `children` function.
|
||||
pub fn into_inner(self) -> Arc<dyn Fn() -> View<T> + Send + Sync> {
|
||||
|
||||
@@ -192,9 +192,6 @@ pub mod callback;
|
||||
/// Types that can be passed as the `children` prop of a component.
|
||||
pub mod children;
|
||||
|
||||
/// Wrapper for intercepting component attributes.
|
||||
pub mod attribute_interceptor;
|
||||
|
||||
#[doc(hidden)]
|
||||
/// Traits used to implement component constructors.
|
||||
pub mod component;
|
||||
|
||||
@@ -26,6 +26,3 @@ temp-env = { version = "0.3.6", features = ["async_closure"] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
@@ -37,6 +37,3 @@ rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["tracing"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_macro"
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/leptos-rs/leptos"
|
||||
@@ -83,4 +83,4 @@ skip_feature_sets = [
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)', 'cfg(erase_components)'] }
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(erase_components)'] }
|
||||
|
||||
@@ -44,6 +44,3 @@ denylist = ["tracing"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
@@ -43,7 +43,7 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
inner: ArcAction<S, Result<S::Output, ServerFnError<S::Error>>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ where
|
||||
inner: ArcAction::new_with_value(err, |input: &S| {
|
||||
S::run_on_client(input.clone())
|
||||
}),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ where
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -114,11 +114,11 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -132,7 +132,7 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
inner: Action<S, Result<S::Output, ServerFnError<S::Error>>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ where
|
||||
inner: Action::new_with_value(err, |input: &S| {
|
||||
S::run_on_client(input.clone())
|
||||
}),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -217,11 +217,11 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::{
|
||||
/// A reference-counted resource that only loads its data locally on the client.
|
||||
pub struct ArcLocalResource<T> {
|
||||
data: ArcAsyncDerived<SendWrapper<T>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ impl<T> Clone for ArcLocalResource<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
data: self.data.clone(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ impl<T> ArcLocalResource<T> {
|
||||
let fut = fetcher();
|
||||
SendWrapper::new(async move { SendWrapper::new(fut.await) })
|
||||
}),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -104,11 +104,11 @@ where
|
||||
|
||||
impl<T> DefinedAt for ArcLocalResource<T> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -200,7 +200,7 @@ impl<T> Subscriber for ArcLocalResource<T> {
|
||||
/// A resource that only loads its data locally on the client.
|
||||
pub struct LocalResource<T> {
|
||||
data: AsyncDerived<SendWrapper<T>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ impl<T> LocalResource<T> {
|
||||
SendWrapper::new(async move { SendWrapper::new(fut.await) })
|
||||
})
|
||||
},
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -287,11 +287,11 @@ where
|
||||
|
||||
impl<T> DefinedAt for LocalResource<T> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -398,7 +398,7 @@ impl<T: 'static> From<ArcLocalResource<T>> for LocalResource<T> {
|
||||
fn from(arc: ArcLocalResource<T>) -> Self {
|
||||
Self {
|
||||
data: arc.data.into(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: arc.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -408,7 +408,7 @@ impl<T: 'static> From<LocalResource<T>> for ArcLocalResource<T> {
|
||||
fn from(local: LocalResource<T>) -> Self {
|
||||
Self {
|
||||
data: local.data.into(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: local.defined_at,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
inner: ArcMultiAction<S, Result<S::Output, ServerFnError<S::Error>>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ where
|
||||
inner: ArcMultiAction::new(|input: &S| {
|
||||
S::run_on_client(input.clone())
|
||||
}),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ where
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -78,11 +78,11 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -96,7 +96,7 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
inner: MultiAction<S, Result<S::Output, ServerFnError<S::Error>>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ where
|
||||
inner: MultiAction::new(|input: &S| {
|
||||
S::run_on_client(input.clone())
|
||||
}),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -176,11 +176,11 @@ where
|
||||
S::Output: 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ pub struct ArcOnceResource<T, Ser = JsonSerdeCodec> {
|
||||
suspenses: Arc<RwLock<Vec<SuspenseContext>>>,
|
||||
loading: Arc<AtomicBool>,
|
||||
ser: PhantomData<fn() -> Ser>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ impl<T, Ser> Clone for ArcOnceResource<T, Ser> {
|
||||
suspenses: self.suspenses.clone(),
|
||||
loading: self.loading.clone(),
|
||||
ser: self.ser,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ where
|
||||
wakers,
|
||||
suspenses,
|
||||
ser: PhantomData,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
};
|
||||
|
||||
@@ -183,11 +183,11 @@ impl<T, Ser> ArcOnceResource<T, Ser> {
|
||||
|
||||
impl<T, Ser> DefinedAt for ArcOnceResource<T, Ser> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
@@ -272,7 +272,7 @@ where
|
||||
|
||||
#[track_caller]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let _guard = SpecialNonReactiveZone::enter();
|
||||
let waker = cx.waker();
|
||||
self.source.track();
|
||||
@@ -491,7 +491,7 @@ where
|
||||
#[derive(Debug)]
|
||||
pub struct OnceResource<T, Ser = JsonSerdeCodec> {
|
||||
inner: ArenaItem<ArcOnceResource<T, Ser>>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -524,13 +524,13 @@ where
|
||||
fut: impl Future<Output = T> + Send + 'static,
|
||||
blocking: bool,
|
||||
) -> Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let defined_at = Location::caller();
|
||||
Self {
|
||||
inner: ArenaItem::new(ArcOnceResource::new_with_options(
|
||||
fut, blocking,
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
}
|
||||
}
|
||||
@@ -551,11 +551,11 @@ where
|
||||
|
||||
impl<T, Ser> DefinedAt for OnceResource<T, Ser> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ pub struct ArcResource<T, Ser = JsonSerdeCodec> {
|
||||
ser: PhantomData<Ser>,
|
||||
refetch: ArcRwSignal<usize>,
|
||||
data: ArcAsyncDerived<T>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ impl<T, Ser> Debug for ArcResource<T, Ser> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut d = f.debug_struct("ArcResource");
|
||||
d.field("ser", &self.ser).field("data", &self.data);
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
d.field("defined_at", self.defined_at);
|
||||
d.finish_non_exhaustive()
|
||||
}
|
||||
@@ -98,7 +98,7 @@ where
|
||||
ser: PhantomData,
|
||||
data: arc_resource.data.into(),
|
||||
refetch: arc_resource.refetch.into(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ where
|
||||
ser: PhantomData,
|
||||
data: resource.data.into(),
|
||||
refetch: resource.refetch.into(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -122,11 +122,11 @@ where
|
||||
|
||||
impl<T, Ser> DefinedAt for ArcResource<T, Ser> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -139,7 +139,7 @@ impl<T, Ser> Clone for ArcResource<T, Ser> {
|
||||
ser: self.ser,
|
||||
refetch: self.refetch.clone(),
|
||||
data: self.data.clone(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -300,7 +300,7 @@ where
|
||||
ser: PhantomData,
|
||||
data,
|
||||
refetch,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -781,7 +781,7 @@ where
|
||||
ser: PhantomData<Ser>,
|
||||
data: AsyncDerived<T>,
|
||||
refetch: RwSignal<usize>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -792,7 +792,7 @@ where
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut d = f.debug_struct("ArcResource");
|
||||
d.field("ser", &self.ser).field("data", &self.data);
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
d.field("defined_at", self.defined_at);
|
||||
d.finish_non_exhaustive()
|
||||
}
|
||||
@@ -803,11 +803,11 @@ where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -1270,7 +1270,7 @@ where
|
||||
ser: PhantomData,
|
||||
data: data.into(),
|
||||
refetch: refetch.into(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_meta"
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/leptos-rs/leptos"
|
||||
@@ -32,6 +32,3 @@ rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["tracing"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
@@ -37,10 +37,14 @@
|
||||
//! }
|
||||
//! ```
|
||||
//! # Feature Flags
|
||||
//! - `csr` Client-side rendering: Generate DOM nodes in the browser
|
||||
//! - `ssr` Server-side rendering: Generate an HTML string (typically on the server)
|
||||
//! - `tracing` Adds integration with the `tracing` crate.
|
||||
//! - `hydrate` Hydration: use this to add interactivity to an SSRed Leptos app
|
||||
//! - `stable` By default, Leptos requires `nightly` Rust, which is what allows the ergonomics
|
||||
//! of calling signals as functions. Enable this feature to support `stable` Rust.
|
||||
//!
|
||||
//! **Important Note:** If you’re using server-side rendering, you should enable `ssr`.
|
||||
//! **Important Note:** You must enable one of `csr`, `hydrate`, or `ssr` to tell Leptos
|
||||
//! which mode your app is operating in.
|
||||
|
||||
use futures::{Stream, StreamExt};
|
||||
use leptos::{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reactive_graph"
|
||||
version = "0.1.1"
|
||||
version = "0.1.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
@@ -47,6 +47,3 @@ rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[package.metadata.cargo-all-features]
|
||||
denylist = ["tracing"]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
|
||||
@@ -101,7 +101,7 @@ pub struct ArcAction<I, O> {
|
||||
action_fn: Arc<
|
||||
dyn Fn(&I) -> Pin<Box<dyn Future<Output = O> + Send>> + Send + Sync,
|
||||
>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ impl<I, O> Clone for ArcAction<I, O> {
|
||||
version: self.version.clone(),
|
||||
dispatched: self.dispatched.clone(),
|
||||
action_fn: self.action_fn.clone(),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ where
|
||||
version: Default::default(),
|
||||
dispatched: Default::default(),
|
||||
action_fn: Arc::new(move |input| Box::pin(action_fn(input))),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -370,7 +370,7 @@ where
|
||||
action_fn: Arc::new(move |input| {
|
||||
Box::pin(SendWrapper::new(action_fn(input)))
|
||||
}),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -502,11 +502,11 @@ where
|
||||
O: 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -592,7 +592,7 @@ where
|
||||
/// ```
|
||||
pub struct Action<I, O, S = SyncStorage> {
|
||||
inner: ArenaItem<ArcAction<I, O>, S>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ where
|
||||
{
|
||||
Self {
|
||||
inner: ArenaItem::new(ArcAction::new(action_fn)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -681,7 +681,7 @@ where
|
||||
{
|
||||
Self {
|
||||
inner: ArenaItem::new(ArcAction::new_with_value(value, action_fn)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -719,7 +719,7 @@ where
|
||||
{
|
||||
Self {
|
||||
inner: ArenaItem::new_local(ArcAction::new_unsync(action_fn)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -737,7 +737,7 @@ where
|
||||
inner: ArenaItem::new_local(ArcAction::new_unsync_with_value(
|
||||
value, action_fn,
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -979,7 +979,7 @@ where
|
||||
inner: ArenaItem::new_with_storage(ArcAction::new_unsync(
|
||||
action_fn,
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -998,7 +998,7 @@ where
|
||||
inner: ArenaItem::new_with_storage(
|
||||
ArcAction::new_unsync_with_value(value, action_fn),
|
||||
),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -1006,11 +1006,11 @@ where
|
||||
|
||||
impl<I, O, S> DefinedAt for Action<I, O, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ use std::{fmt::Debug, future::Future, panic::Location, pin::Pin, sync::Arc};
|
||||
/// ```
|
||||
pub struct MultiAction<I, O, S = SyncStorage> {
|
||||
inner: ArenaItem<ArcMultiAction<I, O>, S>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ where
|
||||
O: 'static,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -130,7 +130,7 @@ where
|
||||
{
|
||||
Self {
|
||||
inner: ArenaItem::new_with_storage(ArcMultiAction::new(action_fn)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ pub struct ArcMemo<T, S = SyncStorage>
|
||||
where
|
||||
S: Storage<T>,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: Arc<RwLock<MemoInner<T, S>>>,
|
||||
}
|
||||
@@ -164,7 +164,7 @@ where
|
||||
RwLock::new(MemoInner::new(Arc::new(fun), subscriber))
|
||||
});
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner,
|
||||
}
|
||||
@@ -177,7 +177,7 @@ where
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
inner: Arc::clone(&self.inner),
|
||||
}
|
||||
@@ -190,11 +190,11 @@ where
|
||||
{
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -272,7 +272,7 @@ where
|
||||
AnySource(
|
||||
Arc::as_ptr(&self.inner) as usize,
|
||||
Arc::downgrade(&self.inner) as Weak<dyn Source + Send + Sync>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
self.defined_at,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ use std::{
|
||||
/// - [`IntoFuture`](std::future::Future) allows you to create a [`Future`] that resolves
|
||||
/// when this resource is done loading.
|
||||
pub struct ArcAsyncDerived<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
// the current state of this signal
|
||||
pub(crate) value: Arc<AsyncRwLock<Option<T>>>,
|
||||
@@ -184,7 +184,7 @@ impl<T> BlockingLock<T> for AsyncRwLock<T> {
|
||||
impl<T> Clone for ArcAsyncDerived<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
value: Arc::clone(&self.value),
|
||||
wakers: Arc::clone(&self.wakers),
|
||||
@@ -197,7 +197,7 @@ impl<T> Clone for ArcAsyncDerived<T> {
|
||||
impl<T> Debug for ArcAsyncDerived<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut f = f.debug_struct("ArcAsyncDerived");
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
f.field("defined_at", &self.defined_at);
|
||||
f.finish_non_exhaustive()
|
||||
}
|
||||
@@ -206,11 +206,11 @@ impl<T> Debug for ArcAsyncDerived<T> {
|
||||
impl<T> DefinedAt for ArcAsyncDerived<T> {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -241,7 +241,7 @@ macro_rules! spawn_derived {
|
||||
let wakers = Arc::new(RwLock::new(Vec::new()));
|
||||
|
||||
let this = ArcAsyncDerived {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::clone(&value),
|
||||
wakers,
|
||||
@@ -632,7 +632,7 @@ impl<T: 'static> ToAnySource for ArcAsyncDerived<T> {
|
||||
AnySource(
|
||||
Arc::as_ptr(&self.inner) as usize,
|
||||
Arc::downgrade(&self.inner) as Weak<dyn Source + Send + Sync>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
self.defined_at,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ use std::{future::Future, ops::DerefMut, panic::Location};
|
||||
/// - [`IntoFuture`](std::future::Future) allows you to create a [`Future`] that resolves
|
||||
/// when this resource is done loading.
|
||||
pub struct AsyncDerived<T, S = SyncStorage> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
pub(crate) inner: ArenaItem<ArcAsyncDerived<T>, S>,
|
||||
}
|
||||
@@ -99,10 +99,10 @@ where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
fn from(value: ArcAsyncDerived<T>) -> Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let defined_at = value.defined_at;
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
@@ -127,10 +127,10 @@ where
|
||||
T: 'static,
|
||||
{
|
||||
fn from_local(value: ArcAsyncDerived<T>) -> Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let defined_at = value.defined_at;
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
@@ -152,7 +152,7 @@ where
|
||||
Fut: Future<Output = T> + Send + 'static,
|
||||
{
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcAsyncDerived::new(fun)),
|
||||
}
|
||||
@@ -170,7 +170,7 @@ where
|
||||
Fut: Future<Output = T> + Send + 'static,
|
||||
{
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(
|
||||
ArcAsyncDerived::new_with_initial(initial_value, fun),
|
||||
@@ -187,7 +187,7 @@ impl<T> AsyncDerived<SendWrapper<T>> {
|
||||
Fut: Future<Output = T> + 'static,
|
||||
{
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcAsyncDerived::new_mock(fun)),
|
||||
}
|
||||
@@ -209,7 +209,7 @@ where
|
||||
Fut: Future<Output = T> + 'static,
|
||||
{
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcAsyncDerived::new_unsync(
|
||||
fun,
|
||||
@@ -230,7 +230,7 @@ where
|
||||
Fut: Future<Output = T> + 'static,
|
||||
{
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(
|
||||
ArcAsyncDerived::new_unsync_with_initial(initial_value, fun),
|
||||
@@ -278,11 +278,11 @@ where
|
||||
impl<T, S> DefinedAt for AsyncDerived<T, S> {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -67,9 +67,7 @@ where
|
||||
fn mark_check(&self) {
|
||||
{
|
||||
let mut lock = self.write().or_poisoned();
|
||||
if lock.state != ReactiveNodeState::Dirty {
|
||||
lock.state = ReactiveNodeState::Check;
|
||||
}
|
||||
lock.state = ReactiveNodeState::Check;
|
||||
}
|
||||
for sub in (&self.read().or_poisoned().subscribers).into_iter() {
|
||||
sub.mark_check();
|
||||
|
||||
@@ -100,7 +100,7 @@ pub struct Memo<T, S = SyncStorage>
|
||||
where
|
||||
S: Storage<T>,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: ArenaItem<ArcMemo<T, S>, S>,
|
||||
}
|
||||
@@ -121,7 +121,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: ArcMemo<T, SyncStorage>) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
@@ -135,7 +135,7 @@ where
|
||||
#[track_caller]
|
||||
fn from_local(value: ArcMemo<T, LocalStorage>) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
@@ -175,7 +175,7 @@ where
|
||||
T: PartialEq,
|
||||
{
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcMemo::new(fun)),
|
||||
}
|
||||
@@ -197,7 +197,7 @@ where
|
||||
changed: fn(Option<&T>, Option<&T>) -> bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcMemo::new_with_compare(
|
||||
fun, changed,
|
||||
@@ -221,7 +221,7 @@ where
|
||||
fun: impl Fn(Option<T>) -> (T, bool) + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcMemo::new_owning(fun)),
|
||||
}
|
||||
@@ -276,11 +276,11 @@ where
|
||||
S: Storage<T>,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ impl<'a> IntoIterator for &'a SourceSet {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[derive(Default, Clone)]
|
||||
pub struct SubscriberSet(Vec<AnySubscriber>);
|
||||
|
||||
impl SubscriberSet {
|
||||
|
||||
@@ -26,17 +26,16 @@ pub trait Source: ReactiveNode {
|
||||
pub struct AnySource(
|
||||
pub(crate) usize,
|
||||
pub(crate) Weak<dyn Source + Send + Sync>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
pub(crate) &'static Location<'static>,
|
||||
#[cfg(debug_assertions)] pub(crate) &'static Location<'static>,
|
||||
);
|
||||
|
||||
impl DefinedAt for AnySource {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.2)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
signal::guards::{Plain, ReadGuard, UntrackedWriteGuard},
|
||||
traits::{DefinedAt, IntoInner, IsDisposed, ReadValue, WriteValue},
|
||||
traits::{DefinedAt, IsDisposed, ReadValue, WriteValue},
|
||||
};
|
||||
use std::{
|
||||
fmt::{Debug, Formatter},
|
||||
@@ -19,7 +19,7 @@ use std::{
|
||||
/// accessing it does not cause effects to subscribe, and
|
||||
/// updating it does not notify anything else.
|
||||
pub struct ArcStoredValue<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
value: Arc<RwLock<T>>,
|
||||
}
|
||||
@@ -27,7 +27,7 @@ pub struct ArcStoredValue<T> {
|
||||
impl<T> Clone for ArcStoredValue<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
value: Arc::clone(&self.value),
|
||||
}
|
||||
@@ -47,7 +47,7 @@ impl<T: Default> Default for ArcStoredValue<T> {
|
||||
#[track_caller]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::new(RwLock::new(T::default())),
|
||||
}
|
||||
@@ -70,11 +70,11 @@ impl<T> Hash for ArcStoredValue<T> {
|
||||
|
||||
impl<T> DefinedAt for ArcStoredValue<T> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -90,7 +90,7 @@ impl<T> ArcStoredValue<T> {
|
||||
#[track_caller]
|
||||
pub fn new(value: T) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::new(RwLock::new(value)),
|
||||
}
|
||||
@@ -124,12 +124,3 @@ impl<T> IsDisposed for ArcStoredValue<T> {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoInner for ArcStoredValue<T> {
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
Some(Arc::into_inner(self.value)?.into_inner().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +121,8 @@ pub mod sandboxed {
|
||||
}
|
||||
|
||||
impl<T> Sandboxed<T> {
|
||||
/// Wraps the given [`Future`], ensuring that any [`ArenaItem`][item] created while it is
|
||||
/// being polled will be associated with the same arena that was active when this was
|
||||
/// called.
|
||||
///
|
||||
/// [item]:[crate::owner::ArenaItem]
|
||||
/// Wraps the given [`Future`], ensuring that any [`ArenaItem`] created while it is being
|
||||
/// polled will be associated with the same arena that was active when this was called.
|
||||
pub fn new(inner: T) -> Self {
|
||||
let arena = MAP.with_borrow(|n| n.as_ref().and_then(Weak::upgrade));
|
||||
Self { arena, inner }
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{
|
||||
arena::{Arena, NodeId},
|
||||
LocalStorage, Storage, SyncStorage, OWNER,
|
||||
};
|
||||
use crate::traits::{Dispose, IntoInner, IsDisposed};
|
||||
use crate::traits::{Dispose, IsDisposed};
|
||||
use send_wrapper::SendWrapper;
|
||||
use std::{any::Any, hash::Hash, marker::PhantomData};
|
||||
|
||||
@@ -134,12 +134,3 @@ impl<T, S> Dispose for ArenaItem<T, S> {
|
||||
Arena::with_mut(|arena| arena.remove(self.node));
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S: Storage<T>> IntoInner for ArenaItem<T, S> {
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
S::take(self.node)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,35 @@ impl Owner {
|
||||
}
|
||||
|
||||
fn use_context<T: Clone + 'static>(&self) -> Option<T> {
|
||||
self.with_context(Clone::clone)
|
||||
let ty = TypeId::of::<T>();
|
||||
let inner = self.inner.read().or_poisoned();
|
||||
let mut parent = inner.parent.as_ref().and_then(|p| p.upgrade());
|
||||
let contexts = &self.inner.read().or_poisoned().contexts;
|
||||
if let Some(context) = contexts.get(&ty) {
|
||||
context.downcast_ref::<T>().cloned()
|
||||
} else {
|
||||
while let Some(ref this_parent) = parent.clone() {
|
||||
let this_parent = this_parent.read().or_poisoned();
|
||||
let contexts = &this_parent.contexts;
|
||||
let value = contexts.get(&ty);
|
||||
let downcast = value
|
||||
.and_then(|context| context.downcast_ref::<T>().cloned());
|
||||
if let Some(value) = downcast {
|
||||
return Some(value);
|
||||
} else {
|
||||
parent =
|
||||
this_parent.parent.as_ref().and_then(|p| p.upgrade());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn take_context<T: 'static>(&self) -> Option<T> {
|
||||
let ty = TypeId::of::<T>();
|
||||
let mut inner = self.inner.write().or_poisoned();
|
||||
let inner = self.inner.read().or_poisoned();
|
||||
let mut parent = inner.parent.as_ref().and_then(|p| p.upgrade());
|
||||
let contexts = &mut inner.contexts;
|
||||
let contexts = &mut self.inner.write().or_poisoned().contexts;
|
||||
if let Some(context) = contexts.remove(&ty) {
|
||||
context.downcast::<T>().ok().map(|n| *n)
|
||||
} else {
|
||||
@@ -43,64 +64,6 @@ impl Owner {
|
||||
}
|
||||
}
|
||||
|
||||
fn with_context<T: 'static, R>(
|
||||
&self,
|
||||
cb: impl FnOnce(&T) -> R,
|
||||
) -> Option<R> {
|
||||
let ty = TypeId::of::<T>();
|
||||
let inner = self.inner.read().or_poisoned();
|
||||
let mut parent = inner.parent.as_ref().and_then(|p| p.upgrade());
|
||||
let contexts = &inner.contexts;
|
||||
let reference = if let Some(context) = contexts.get(&ty) {
|
||||
context.downcast_ref::<T>()
|
||||
} else {
|
||||
while let Some(ref this_parent) = parent.clone() {
|
||||
let this_parent = this_parent.read().or_poisoned();
|
||||
let contexts = &this_parent.contexts;
|
||||
let value = contexts.get(&ty);
|
||||
let downcast =
|
||||
value.and_then(|context| context.downcast_ref::<T>());
|
||||
if let Some(value) = downcast {
|
||||
return Some(cb(value));
|
||||
} else {
|
||||
parent =
|
||||
this_parent.parent.as_ref().and_then(|p| p.upgrade());
|
||||
}
|
||||
}
|
||||
None
|
||||
};
|
||||
reference.map(cb)
|
||||
}
|
||||
|
||||
fn update_context<T: 'static, R>(
|
||||
&self,
|
||||
cb: impl FnOnce(&mut T) -> R,
|
||||
) -> Option<R> {
|
||||
let ty = TypeId::of::<T>();
|
||||
let mut inner = self.inner.write().or_poisoned();
|
||||
let mut parent = inner.parent.as_ref().and_then(|p| p.upgrade());
|
||||
let contexts = &mut inner.contexts;
|
||||
let reference = if let Some(context) = contexts.get_mut(&ty) {
|
||||
context.downcast_mut::<T>()
|
||||
} else {
|
||||
while let Some(ref this_parent) = parent.clone() {
|
||||
let mut this_parent = this_parent.write().or_poisoned();
|
||||
let contexts = &mut this_parent.contexts;
|
||||
let value = contexts.get_mut(&ty);
|
||||
let downcast =
|
||||
value.and_then(|context| context.downcast_mut::<T>());
|
||||
if let Some(value) = downcast {
|
||||
return Some(cb(value));
|
||||
} else {
|
||||
parent =
|
||||
this_parent.parent.as_ref().and_then(|p| p.upgrade());
|
||||
}
|
||||
}
|
||||
None
|
||||
};
|
||||
reference.map(cb)
|
||||
}
|
||||
|
||||
/// Searches for items stored in context in either direction, either among parents or among
|
||||
/// descendants.
|
||||
pub fn use_context_bidirectional<T: Clone + 'static>(&self) -> Option<T> {
|
||||
@@ -356,86 +319,3 @@ pub fn expect_context<T: Clone + 'static>() -> T {
|
||||
pub fn take_context<T: 'static>() -> Option<T> {
|
||||
Owner::current().and_then(|owner| owner.take_context())
|
||||
}
|
||||
|
||||
/// Access a reference to a context value of type `T` in the reactive system.
|
||||
///
|
||||
/// This traverses the reactive ownership graph, beginning from the current reactive
|
||||
/// [`Owner`] and iterating through its parents, if any. When the value is found,
|
||||
/// the function that you pass is applied to an immutable reference to it.
|
||||
///
|
||||
/// The context value should have been provided elsewhere using
|
||||
/// [`provide_context`](provide_context).
|
||||
///
|
||||
/// This is useful for passing values down to components or functions lower in a
|
||||
/// hierarchy without needs to “prop drill” by passing them through each layer as
|
||||
/// arguments to a function or properties of a component.
|
||||
///
|
||||
/// Context works similarly to variable scope: a context that is provided higher in
|
||||
/// the reactive graph can be used lower down, but a context that is provided lower
|
||||
/// in the tree cannot be used higher up.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use reactive_graph::prelude::*;
|
||||
/// # use reactive_graph::owner::*;
|
||||
/// # let owner = Owner::new(); owner.set();
|
||||
/// # use reactive_graph::effect::Effect;
|
||||
/// # futures::executor::block_on(async move {
|
||||
/// # any_spawner::Executor::init_futures_executor();
|
||||
/// Effect::new(move |_| {
|
||||
/// provide_context(String::from("foo"));
|
||||
///
|
||||
/// Effect::new(move |_| {
|
||||
/// let value = with_context::<String, _>(|val| val.to_string())
|
||||
/// .expect("could not find String in context");
|
||||
/// assert_eq!(value, "foo");
|
||||
/// });
|
||||
/// });
|
||||
/// # });
|
||||
/// ```
|
||||
pub fn with_context<T: 'static, R>(cb: impl FnOnce(&T) -> R) -> Option<R> {
|
||||
Owner::current().and_then(|owner| owner.with_context(cb))
|
||||
}
|
||||
|
||||
/// Update a context value of type `T` in the reactive system.
|
||||
///
|
||||
/// This traverses the reactive ownership graph, beginning from the current reactive
|
||||
/// [`Owner`] and iterating through its parents, if any. When the value is found,
|
||||
/// the function that you pass is applied to a mutable reference to it.
|
||||
///
|
||||
/// The context value should have been provided elsewhere using
|
||||
/// [`provide_context`](provide_context).
|
||||
///
|
||||
/// This is useful for passing values down to components or functions lower in a
|
||||
/// hierarchy without needs to “prop drill” by passing them through each layer as
|
||||
/// arguments to a function or properties of a component.
|
||||
///
|
||||
/// Context works similarly to variable scope: a context that is provided higher in
|
||||
/// the reactive graph can be used lower down, but a context that is provided lower
|
||||
/// in the tree cannot be used higher up.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use reactive_graph::prelude::*;
|
||||
/// # use reactive_graph::owner::*;
|
||||
/// # let owner = Owner::new(); owner.set();
|
||||
/// # use reactive_graph::effect::Effect;
|
||||
/// # futures::executor::block_on(async move {
|
||||
/// # any_spawner::Executor::init_futures_executor();
|
||||
/// Effect::new(move |_| {
|
||||
/// provide_context(String::from("foo"));
|
||||
///
|
||||
/// Effect::new(move |_| {
|
||||
/// let value = update_context::<String, _>(|val| {
|
||||
/// std::mem::replace(val, "bar".to_string())
|
||||
/// })
|
||||
/// .expect("could not find String in context");
|
||||
/// assert_eq!(value, "foo");
|
||||
/// assert_eq!(expect_context::<String>(), "bar");
|
||||
/// });
|
||||
/// });
|
||||
/// # });
|
||||
/// ```
|
||||
pub fn update_context<T: 'static, R>(
|
||||
cb: impl FnOnce(&mut T) -> R,
|
||||
) -> Option<R> {
|
||||
Owner::current().and_then(|owner| owner.update_context(cb))
|
||||
}
|
||||
|
||||
@@ -54,10 +54,6 @@ pub trait Storage<T>: Send + Sync + 'static {
|
||||
|
||||
/// Sets a new value for the stored value. If it has been disposed, returns `Some(T)`.
|
||||
fn try_set(node: NodeId, value: T) -> Option<T>;
|
||||
|
||||
/// Takes an item from the arena if it exists and can be accessed from this thread.
|
||||
/// If it cannot be casted, it will still be removed from the arena.
|
||||
fn take(node: NodeId) -> Option<T>;
|
||||
}
|
||||
|
||||
/// A form of [`Storage`] that stores the type as itself, with no wrapper.
|
||||
@@ -104,16 +100,6 @@ where
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn take(node: NodeId) -> Option<T> {
|
||||
Arena::with_mut(|arena| {
|
||||
let m = arena.remove(node)?;
|
||||
match m.downcast::<T>() {
|
||||
Ok(inner) => Some(*inner),
|
||||
Err(_) => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A form of [`Storage`] that stores the type with a wrapper that makes it `Send + Sync`, but only
|
||||
@@ -162,14 +148,4 @@ where
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn take(node: NodeId) -> Option<T> {
|
||||
Arena::with_mut(|arena| {
|
||||
let m = arena.remove(node)?;
|
||||
match m.downcast::<SendWrapper<T>>() {
|
||||
Ok(inner) => Some(inner.take()),
|
||||
Err(_) => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
signal::guards::{Plain, ReadGuard, UntrackedWriteGuard},
|
||||
traits::{
|
||||
DefinedAt, Dispose, IntoInner, IsDisposed, ReadValue, WriteValue,
|
||||
},
|
||||
traits::{DefinedAt, Dispose, IsDisposed, ReadValue, WriteValue},
|
||||
unwrap_signal,
|
||||
};
|
||||
use std::{
|
||||
@@ -24,7 +22,7 @@ use std::{
|
||||
/// updating it does not notify anything else.
|
||||
pub struct StoredValue<T, S = SyncStorage> {
|
||||
value: ArenaItem<ArcStoredValue<T>, S>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
}
|
||||
|
||||
@@ -64,11 +62,11 @@ impl<T, S> Hash for StoredValue<T, S> {
|
||||
|
||||
impl<T, S> DefinedAt for StoredValue<T, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -85,7 +83,7 @@ where
|
||||
pub fn new_with_storage(value: T) -> Self {
|
||||
Self {
|
||||
value: ArenaItem::new_with_storage(ArcStoredValue::new(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -164,19 +162,6 @@ impl<T, S> Dispose for StoredValue<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> IntoInner for StoredValue<T, S>
|
||||
where
|
||||
T: 'static,
|
||||
S: Storage<ArcStoredValue<T>>,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
self.value.into_inner()?.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ArcStoredValue<T>> for StoredValue<T>
|
||||
where
|
||||
T: Send + Sync + 'static,
|
||||
@@ -184,7 +169,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: ArcStoredValue<T>) -> Self {
|
||||
StoredValue {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: ArenaItem::new(value),
|
||||
}
|
||||
|
||||
@@ -113,8 +113,7 @@ pub fn arc_signal<T>(value: T) -> (ArcReadSignal<T>, ArcWriteSignal<T>) {
|
||||
pub fn signal<T: Send + Sync + 'static>(
|
||||
value: T,
|
||||
) -> (ReadSignal<T>, WriteSignal<T>) {
|
||||
let (r, w) = arc_signal(value);
|
||||
(r.into(), w.into())
|
||||
RwSignal::new(value).split()
|
||||
}
|
||||
|
||||
/// Creates an arena-allocated signal.
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
graph::SubscriberSet,
|
||||
traits::{DefinedAt, IntoInner, IsDisposed, ReadUntracked},
|
||||
traits::{DefinedAt, IsDisposed, ReadUntracked},
|
||||
};
|
||||
use core::fmt::{Debug, Formatter, Result};
|
||||
use std::{
|
||||
@@ -54,7 +54,7 @@ use std::{
|
||||
/// assert_eq!(count.read(), 0);
|
||||
/// ```
|
||||
pub struct ArcReadSignal<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) value: Arc<RwLock<T>>,
|
||||
pub(crate) inner: Arc<RwLock<SubscriberSet>>,
|
||||
@@ -64,7 +64,7 @@ impl<T> Clone for ArcReadSignal<T> {
|
||||
#[track_caller]
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
value: Arc::clone(&self.value),
|
||||
inner: Arc::clone(&self.inner),
|
||||
@@ -85,7 +85,7 @@ impl<T: Default> Default for ArcReadSignal<T> {
|
||||
#[track_caller]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::new(RwLock::new(T::default())),
|
||||
inner: Arc::new(RwLock::new(SubscriberSet::new())),
|
||||
@@ -110,11 +110,11 @@ impl<T> Hash for ArcReadSignal<T> {
|
||||
impl<T> DefinedAt for ArcReadSignal<T> {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -128,15 +128,6 @@ impl<T> IsDisposed for ArcReadSignal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoInner for ArcReadSignal<T> {
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
Some(Arc::into_inner(self.value)?.into_inner().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsSubscriberSet for ArcReadSignal<T> {
|
||||
type Output = Arc<RwLock<SubscriberSet>>;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{
|
||||
use crate::{
|
||||
graph::{ReactiveNode, SubscriberSet},
|
||||
prelude::{IsDisposed, Notify},
|
||||
traits::{DefinedAt, IntoInner, ReadUntracked, UntrackableGuard, Write},
|
||||
traits::{DefinedAt, ReadUntracked, UntrackableGuard, Write},
|
||||
};
|
||||
use core::fmt::{Debug, Formatter, Result};
|
||||
use std::{
|
||||
@@ -94,7 +94,7 @@ use std::{
|
||||
/// assert_eq!(double_count(), 2);
|
||||
/// ```
|
||||
pub struct ArcRwSignal<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) value: Arc<RwLock<T>>,
|
||||
pub(crate) inner: Arc<RwLock<SubscriberSet>>,
|
||||
@@ -104,7 +104,7 @@ impl<T> Clone for ArcRwSignal<T> {
|
||||
#[track_caller]
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
value: Arc::clone(&self.value),
|
||||
inner: Arc::clone(&self.inner),
|
||||
@@ -154,7 +154,7 @@ impl<T> ArcRwSignal<T> {
|
||||
#[track_caller]
|
||||
pub fn new(value: T) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::new(RwLock::new(value)),
|
||||
inner: Arc::new(RwLock::new(SubscriberSet::new())),
|
||||
@@ -165,7 +165,7 @@ impl<T> ArcRwSignal<T> {
|
||||
#[track_caller]
|
||||
pub fn read_only(&self) -> ArcReadSignal<T> {
|
||||
ArcReadSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::clone(&self.value),
|
||||
inner: Arc::clone(&self.inner),
|
||||
@@ -176,7 +176,7 @@ impl<T> ArcRwSignal<T> {
|
||||
#[track_caller]
|
||||
pub fn write_only(&self) -> ArcWriteSignal<T> {
|
||||
ArcWriteSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::clone(&self.value),
|
||||
inner: Arc::clone(&self.inner),
|
||||
@@ -198,7 +198,7 @@ impl<T> ArcRwSignal<T> {
|
||||
) -> Option<Self> {
|
||||
if Arc::ptr_eq(&read.inner, &write.inner) {
|
||||
Some(Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: read.value,
|
||||
inner: read.inner,
|
||||
@@ -212,11 +212,11 @@ impl<T> ArcRwSignal<T> {
|
||||
impl<T> DefinedAt for ArcRwSignal<T> {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -230,15 +230,6 @@ impl<T> IsDisposed for ArcRwSignal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoInner for ArcRwSignal<T> {
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
Some(Arc::into_inner(self.value)?.into_inner().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AsSubscriberSet for ArcRwSignal<T> {
|
||||
type Output = Arc<RwLock<SubscriberSet>>;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::{
|
||||
///
|
||||
/// This can be useful for when using external data not stored in signals, for example.
|
||||
pub struct ArcTrigger {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) inner: Arc<RwLock<SubscriberSet>>,
|
||||
}
|
||||
@@ -23,7 +23,7 @@ impl ArcTrigger {
|
||||
#[track_caller]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: Default::default(),
|
||||
}
|
||||
@@ -40,7 +40,7 @@ impl Clone for ArcTrigger {
|
||||
#[track_caller]
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
inner: Arc::clone(&self.inner),
|
||||
}
|
||||
@@ -72,11 +72,11 @@ impl AsSubscriberSet for ArcTrigger {
|
||||
impl DefinedAt for ArcTrigger {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::guards::{UntrackedWriteGuard, WriteGuard};
|
||||
use crate::{
|
||||
graph::{ReactiveNode, SubscriberSet},
|
||||
prelude::{IsDisposed, Notify},
|
||||
traits::{DefinedAt, IntoInner, UntrackableGuard, Write},
|
||||
traits::{DefinedAt, UntrackableGuard, Write},
|
||||
};
|
||||
use core::fmt::{Debug, Formatter, Result};
|
||||
use std::{
|
||||
@@ -54,7 +54,7 @@ use std::{
|
||||
/// assert_eq!(count.get(), 3);
|
||||
/// ```
|
||||
pub struct ArcWriteSignal<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) value: Arc<RwLock<T>>,
|
||||
pub(crate) inner: Arc<RwLock<SubscriberSet>>,
|
||||
@@ -64,7 +64,7 @@ impl<T> Clone for ArcWriteSignal<T> {
|
||||
#[track_caller]
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
value: Arc::clone(&self.value),
|
||||
inner: Arc::clone(&self.inner),
|
||||
@@ -98,11 +98,11 @@ impl<T> Hash for ArcWriteSignal<T> {
|
||||
impl<T> DefinedAt for ArcWriteSignal<T> {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -116,15 +116,6 @@ impl<T> IsDisposed for ArcWriteSignal<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoInner for ArcWriteSignal<T> {
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
Some(Arc::into_inner(self.value)?.into_inner().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Notify for ArcWriteSignal<T> {
|
||||
fn notify(&self) {
|
||||
self.inner.mark_dirty();
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{
|
||||
use crate::{
|
||||
graph::SubscriberSet,
|
||||
owner::{ArenaItem, FromLocal, LocalStorage, Storage, SyncStorage},
|
||||
traits::{DefinedAt, Dispose, IntoInner, IsDisposed, ReadUntracked},
|
||||
traits::{DefinedAt, Dispose, IsDisposed, ReadUntracked},
|
||||
unwrap_signal,
|
||||
};
|
||||
use core::fmt::Debug;
|
||||
@@ -58,7 +58,7 @@ use std::{
|
||||
/// assert_eq!(count.read(), 0);
|
||||
/// ```
|
||||
pub struct ReadSignal<T, S = SyncStorage> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) inner: ArenaItem<ArcReadSignal<T>, S>,
|
||||
}
|
||||
@@ -105,11 +105,11 @@ impl<T, S> Hash for ReadSignal<T, S> {
|
||||
|
||||
impl<T, S> DefinedAt for ReadSignal<T, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -122,18 +122,6 @@ impl<T, S> IsDisposed for ReadSignal<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> IntoInner for ReadSignal<T, S>
|
||||
where
|
||||
S: Storage<ArcReadSignal<T>>,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
self.inner.into_inner()?.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> AsSubscriberSet for ReadSignal<T, S>
|
||||
where
|
||||
S: Storage<ArcReadSignal<T>>,
|
||||
@@ -168,7 +156,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: ArcReadSignal<T>) -> Self {
|
||||
ReadSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
@@ -182,7 +170,7 @@ where
|
||||
#[track_caller]
|
||||
fn from_local(value: ArcReadSignal<T>) -> Self {
|
||||
ReadSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
owner::{ArenaItem, FromLocal, LocalStorage, Storage, SyncStorage},
|
||||
signal::guards::{UntrackedWriteGuard, WriteGuard},
|
||||
traits::{
|
||||
DefinedAt, Dispose, IntoInner, IsDisposed, Notify, ReadUntracked,
|
||||
DefinedAt, Dispose, IsDisposed, Notify, ReadUntracked,
|
||||
UntrackableGuard, Write,
|
||||
},
|
||||
unwrap_signal,
|
||||
@@ -100,7 +100,7 @@ use std::{
|
||||
/// assert_eq!(double_count(), 2);
|
||||
/// ```
|
||||
pub struct RwSignal<T, S = SyncStorage> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: ArenaItem<ArcRwSignal<T>, S>,
|
||||
}
|
||||
@@ -139,7 +139,7 @@ where
|
||||
#[track_caller]
|
||||
pub fn new_with_storage(value: T) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcRwSignal::new(value)),
|
||||
}
|
||||
@@ -172,7 +172,7 @@ where
|
||||
#[track_caller]
|
||||
pub fn read_only(&self) -> ReadSignal<T, S> {
|
||||
ReadSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(
|
||||
self.inner
|
||||
@@ -194,7 +194,7 @@ where
|
||||
#[track_caller]
|
||||
pub fn write_only(&self) -> WriteSignal<T, S> {
|
||||
WriteSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(
|
||||
self.inner
|
||||
@@ -231,10 +231,10 @@ where
|
||||
(Some(read), Some(write)) => {
|
||||
if Arc::ptr_eq(&read.inner, &write.inner) {
|
||||
Some(Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcRwSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::clone(&read.value),
|
||||
inner: Arc::clone(&read.inner),
|
||||
@@ -296,11 +296,11 @@ impl<T, S> Hash for RwSignal<T, S> {
|
||||
|
||||
impl<T, S> DefinedAt for RwSignal<T, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -313,18 +313,6 @@ impl<T: 'static, S> IsDisposed for RwSignal<T, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> IntoInner for RwSignal<T, S>
|
||||
where
|
||||
S: Storage<ArcRwSignal<T>>,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
self.inner.into_inner()?.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> AsSubscriberSet for RwSignal<T, S>
|
||||
where
|
||||
S: Storage<ArcRwSignal<T>>,
|
||||
@@ -390,7 +378,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: ArcRwSignal<T>) -> Self {
|
||||
RwSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
@@ -414,7 +402,7 @@ where
|
||||
#[track_caller]
|
||||
fn from_local(value: ArcRwSignal<T>) -> Self {
|
||||
RwSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ where
|
||||
AnySource(
|
||||
Arc::as_ptr(subs) as usize,
|
||||
Arc::downgrade(subs) as Weak<dyn Source + Send + Sync>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
self.defined_at().expect("no DefinedAt in debug mode"),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::{
|
||||
/// [`Owner`](crate::owner::Owner) cleans up. For a reference-counted trigger that lives
|
||||
/// as long as a reference to it is alive, see [`ArcTrigger`].
|
||||
pub struct Trigger {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) inner: ArenaItem<ArcTrigger>,
|
||||
}
|
||||
@@ -28,7 +28,7 @@ impl Trigger {
|
||||
#[track_caller]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new(ArcTrigger::new()),
|
||||
}
|
||||
@@ -83,11 +83,11 @@ impl AsSubscriberSet for Trigger {
|
||||
impl DefinedAt for Trigger {
|
||||
#[inline(always)]
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use super::{guards::WriteGuard, ArcWriteSignal};
|
||||
use crate::{
|
||||
owner::{ArenaItem, FromLocal, LocalStorage, Storage, SyncStorage},
|
||||
traits::{
|
||||
DefinedAt, Dispose, IntoInner, IsDisposed, Notify, UntrackableGuard,
|
||||
Write,
|
||||
},
|
||||
owner::{ArenaItem, Storage, SyncStorage},
|
||||
traits::{DefinedAt, Dispose, IsDisposed, Notify, UntrackableGuard, Write},
|
||||
};
|
||||
use core::fmt::Debug;
|
||||
use guardian::ArcRwLockWriteGuardian;
|
||||
@@ -53,7 +50,7 @@ use std::{hash::Hash, ops::DerefMut, panic::Location, sync::Arc};
|
||||
/// assert_eq!(count.get(), 3);
|
||||
/// ```
|
||||
pub struct WriteSignal<T, S = SyncStorage> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) inner: ArenaItem<ArcWriteSignal<T>, S>,
|
||||
}
|
||||
@@ -100,63 +97,23 @@ impl<T, S> Hash for WriteSignal<T, S> {
|
||||
|
||||
impl<T, S> DefinedAt for WriteSignal<T, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ArcWriteSignal<T>> for WriteSignal<T>
|
||||
where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
#[track_caller]
|
||||
fn from(value: ArcWriteSignal<T>) -> Self {
|
||||
WriteSignal {
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FromLocal<ArcWriteSignal<T>> for WriteSignal<T, LocalStorage>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
#[track_caller]
|
||||
fn from_local(value: ArcWriteSignal<T>) -> Self {
|
||||
WriteSignal {
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> IsDisposed for WriteSignal<T, S> {
|
||||
fn is_disposed(&self) -> bool {
|
||||
self.inner.is_disposed()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> IntoInner for WriteSignal<T, S>
|
||||
where
|
||||
S: Storage<ArcWriteSignal<T>>,
|
||||
{
|
||||
type Value = T;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_inner(self) -> Option<Self::Value> {
|
||||
self.inner.into_inner()?.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> Notify for WriteSignal<T, S>
|
||||
where
|
||||
T: 'static,
|
||||
|
||||
@@ -67,10 +67,10 @@ use std::{
|
||||
#[macro_export]
|
||||
macro_rules! unwrap_signal {
|
||||
($signal:ident) => {{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let location = std::panic::Location::caller();
|
||||
|| {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
panic!(
|
||||
"{}",
|
||||
@@ -80,7 +80,7 @@ macro_rules! unwrap_signal {
|
||||
)
|
||||
);
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
panic!(
|
||||
"Tried to access a reactive value that has already been \
|
||||
@@ -630,18 +630,6 @@ pub trait IsDisposed {
|
||||
fn is_disposed(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Turns a signal back into a raw value.
|
||||
pub trait IntoInner {
|
||||
/// The type of the value contained in the signal.
|
||||
type Value;
|
||||
|
||||
/// Returns the inner value if this is the only reference to to the signal.
|
||||
/// Otherwise, returns `None` and drops this reference.
|
||||
/// # Panics
|
||||
/// Panics if the inner lock is poisoned.
|
||||
fn into_inner(self) -> Option<Self::Value>;
|
||||
}
|
||||
|
||||
/// Describes where the signal was defined. This is used for diagnostic warnings and is purely a
|
||||
/// debug-mode tool.
|
||||
pub trait DefinedAt {
|
||||
|
||||
@@ -93,35 +93,17 @@ pub mod read {
|
||||
}
|
||||
|
||||
/// A wrapper for any kind of reference-counted reactive signal:
|
||||
/// an [`ArcReadSignal`], [`ArcMemo`], [`ArcRwSignal`], or derived signal closure,
|
||||
/// or a plain value of the same type
|
||||
/// an [`ArcReadSignal`], [`ArcMemo`], [`ArcRwSignal`],
|
||||
/// or derived signal closure.
|
||||
///
|
||||
/// This allows you to create APIs that take `T` or any reactive value that returns `T`
|
||||
/// as an argument, rather than adding a generic `F: Fn() -> T`.
|
||||
///
|
||||
/// Values can be accessed with the same function call, `read()`, `with()`, and `get()`
|
||||
/// APIs as other signals.
|
||||
///
|
||||
/// ## Important Notes about Derived Signals
|
||||
///
|
||||
/// `Signal::derive()` is simply a way to box and type-erase a “derived signal,” which
|
||||
/// is a plain closure that accesses one or more signals. It does *not* cache the value
|
||||
/// of that computation. Accessing the value of a `Signal<_>` that is created using `Signal::derive()`
|
||||
/// will run the closure again every time you call `.read()`, `.with()`, or `.get()`.
|
||||
///
|
||||
/// If you want the closure to run the minimal number of times necessary to update its state,
|
||||
/// and then to cache its value, you should use a [`Memo`] (and convert it into a `Signal<_>`)
|
||||
/// rather than using `Signal::derive()`.
|
||||
///
|
||||
/// Note that for many computations, it is nevertheless less expensive to use a derived signal
|
||||
/// than to create a separate memo and to cache the value: creating a new reactive node and
|
||||
/// taking the lock on that cached value whenever you access the signal is *more* expensive than
|
||||
/// simply re-running the calculation in many cases.
|
||||
/// This allows you to create APIs that take any kind of `ArcSignal<T>` as an argument,
|
||||
/// rather than adding a generic `F: Fn() -> T`. Values can be access with the same
|
||||
/// function call, `with()`, and `get()` APIs as other signals.
|
||||
pub struct ArcSignal<T: 'static, S = SyncStorage>
|
||||
where
|
||||
S: Storage<T>,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: SignalTypes<T, S>,
|
||||
}
|
||||
@@ -132,7 +114,7 @@ pub mod read {
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
inner: self.inner.clone(),
|
||||
}
|
||||
@@ -146,7 +128,7 @@ pub mod read {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut s = f.debug_struct("ArcSignal");
|
||||
s.field("inner", &self.inner);
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
s.field("defined_at", &self.defined_at);
|
||||
s.finish()
|
||||
}
|
||||
@@ -202,7 +184,7 @@ pub mod read {
|
||||
|
||||
Self {
|
||||
inner: SignalTypes::DerivedSignal(Arc::new(derived_signal)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -212,7 +194,7 @@ pub mod read {
|
||||
pub fn stored(value: T) -> Self {
|
||||
Self {
|
||||
inner: SignalTypes::Stored(ArcStoredValue::new(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -232,7 +214,7 @@ pub mod read {
|
||||
fn from(value: ArcReadSignal<T>) -> Self {
|
||||
Self {
|
||||
inner: SignalTypes::ReadSignal(value),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -243,7 +225,7 @@ pub mod read {
|
||||
fn from(value: ArcRwSignal<T>) -> Self {
|
||||
Self {
|
||||
inner: SignalTypes::ReadSignal(value.read_only()),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -257,7 +239,7 @@ pub mod read {
|
||||
fn from(value: ArcMemo<T, S>) -> Self {
|
||||
Self {
|
||||
inner: SignalTypes::Memo(value),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -268,11 +250,11 @@ pub mod read {
|
||||
S: Storage<T>,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -348,35 +330,16 @@ pub mod read {
|
||||
}
|
||||
|
||||
/// A wrapper for any kind of arena-allocated reactive signal:
|
||||
/// a [`ReadSignal`], [`Memo`], [`RwSignal`], or derived signal closure,
|
||||
/// or a plain value of the same type
|
||||
/// an [`ReadSignal`], [`Memo`], [`RwSignal`], or derived signal closure.
|
||||
///
|
||||
/// This allows you to create APIs that take `T` or any reactive value that returns `T`
|
||||
/// as an argument, rather than adding a generic `F: Fn() -> T`.
|
||||
///
|
||||
/// Values can be accessed with the same function call, `read()`, `with()`, and `get()`
|
||||
/// APIs as other signals.
|
||||
///
|
||||
/// ## Important Notes about Derived Signals
|
||||
///
|
||||
/// `Signal::derive()` is simply a way to box and type-erase a “derived signal,” which
|
||||
/// is a plain closure that accesses one or more signals. It does *not* cache the value
|
||||
/// of that computation. Accessing the value of a `Signal<_>` that is created using `Signal::derive()`
|
||||
/// will run the closure again every time you call `.read()`, `.with()`, or `.get()`.
|
||||
///
|
||||
/// If you want the closure to run the minimal number of times necessary to update its state,
|
||||
/// and then to cache its value, you should use a [`Memo`] (and convert it into a `Signal<_>`)
|
||||
/// rather than using `Signal::derive()`.
|
||||
///
|
||||
/// Note that for many computations, it is nevertheless less expensive to use a derived signal
|
||||
/// than to create a separate memo and to cache the value: creating a new reactive node and
|
||||
/// taking the lock on that cached value whenever you access the signal is *more* expensive than
|
||||
/// simply re-running the calculation in many cases.
|
||||
/// This allows you to create APIs that take any kind of `Signal<T>` as an argument,
|
||||
/// rather than adding a generic `F: Fn() -> T`. Values can be access with the same
|
||||
/// function call, `with()`, and `get()` APIs as other signals.
|
||||
pub struct Signal<T, S = SyncStorage>
|
||||
where
|
||||
S: Storage<T>,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: ArenaItem<SignalTypes<T, S>, S>,
|
||||
}
|
||||
@@ -408,7 +371,7 @@ pub mod read {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut s = f.debug_struct("Signal");
|
||||
s.field("inner", &self.inner);
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
s.field("defined_at", &self.defined_at);
|
||||
s.finish()
|
||||
}
|
||||
@@ -430,11 +393,11 @@ pub mod read {
|
||||
S: Storage<T>,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -567,7 +530,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_with_storage(SignalTypes::DerivedSignal(
|
||||
Arc::new(derived_signal),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -579,7 +542,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_with_storage(SignalTypes::Stored(
|
||||
ArcStoredValue::new(value),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -606,7 +569,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_local(SignalTypes::DerivedSignal(
|
||||
Arc::new(derived_signal),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -619,7 +582,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_local(SignalTypes::Stored(
|
||||
ArcStoredValue::new(value),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -677,7 +640,7 @@ pub mod read {
|
||||
#[track_caller]
|
||||
fn from(value: ArcSignal<T, SyncStorage>) -> Self {
|
||||
Signal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new(value.inner),
|
||||
}
|
||||
@@ -691,7 +654,7 @@ pub mod read {
|
||||
#[track_caller]
|
||||
fn from_local(value: ArcSignal<T, LocalStorage>) -> Self {
|
||||
Signal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_local(value.inner),
|
||||
}
|
||||
@@ -705,7 +668,7 @@ pub mod read {
|
||||
#[track_caller]
|
||||
fn from(value: Signal<T, S>) -> Self {
|
||||
ArcSignal {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: value
|
||||
.inner
|
||||
@@ -723,7 +686,7 @@ pub mod read {
|
||||
fn from(value: ReadSignal<T>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new(SignalTypes::ReadSignal(value.into())),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -739,7 +702,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_local(SignalTypes::ReadSignal(
|
||||
value.into(),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -753,7 +716,7 @@ pub mod read {
|
||||
fn from(value: ArcReadSignal<T>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new(SignalTypes::ReadSignal(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -767,7 +730,7 @@ pub mod read {
|
||||
fn from(value: ArcReadSignal<T>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new_local(SignalTypes::ReadSignal(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -783,7 +746,7 @@ pub mod read {
|
||||
inner: ArenaItem::new(SignalTypes::ReadSignal(
|
||||
value.read_only().into(),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -799,7 +762,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_local(SignalTypes::ReadSignal(
|
||||
value.read_only().into(),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -815,7 +778,7 @@ pub mod read {
|
||||
inner: ArenaItem::new(SignalTypes::ReadSignal(
|
||||
value.read_only(),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -831,7 +794,7 @@ pub mod read {
|
||||
inner: ArenaItem::new_local(SignalTypes::ReadSignal(
|
||||
value.read_only(),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -845,7 +808,7 @@ pub mod read {
|
||||
fn from(value: Memo<T>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new(SignalTypes::Memo(value.into())),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -859,7 +822,7 @@ pub mod read {
|
||||
fn from(value: Memo<T, LocalStorage>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new_local(SignalTypes::Memo(value.into())),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -873,7 +836,7 @@ pub mod read {
|
||||
fn from(value: ArcMemo<T>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new(SignalTypes::Memo(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -887,7 +850,7 @@ pub mod read {
|
||||
fn from(value: ArcMemo<T, LocalStorage>) -> Self {
|
||||
Self {
|
||||
inner: ArenaItem::new_local(SignalTypes::Memo(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -1868,7 +1831,7 @@ pub mod write {
|
||||
T: 'static,
|
||||
{
|
||||
inner: SignalSetterTypes<T, S>,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static std::panic::Location<'static>,
|
||||
}
|
||||
|
||||
@@ -1883,7 +1846,7 @@ pub mod write {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
inner: SignalSetterTypes::Default,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -1936,7 +1899,7 @@ pub mod write {
|
||||
inner: SignalSetterTypes::Mapped(ArenaItem::new_with_storage(
|
||||
Box::new(mapped_setter),
|
||||
)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -1947,7 +1910,7 @@ pub mod write {
|
||||
fn from(value: WriteSignal<T, S>) -> Self {
|
||||
Self {
|
||||
inner: SignalSetterTypes::Write(value),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
@@ -1962,7 +1925,7 @@ pub mod write {
|
||||
fn from(value: RwSignal<T, S>) -> Self {
|
||||
Self {
|
||||
inner: SignalSetterTypes::Write(value.write_only()),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,43 +443,3 @@ fn unsync_derived_signal_and_memo() {
|
||||
assert_eq!(f.with(|n| *n), 6);
|
||||
assert_eq!(f.get_untracked(), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memo_updates_even_if_not_read_until_later() {
|
||||
#![allow(clippy::bool_assert_comparison)]
|
||||
|
||||
let owner = Owner::new();
|
||||
owner.set();
|
||||
|
||||
// regression test for https://github.com/leptos-rs/leptos/issues/3339
|
||||
|
||||
let input = RwSignal::new(0);
|
||||
let first_memo = Memo::new(move |_| input.get() == 1);
|
||||
let second_memo = Memo::new(move |_| first_memo.get());
|
||||
|
||||
assert_eq!(input.get(), 0);
|
||||
assert_eq!(first_memo.get(), false);
|
||||
|
||||
println!("update to 1");
|
||||
input.set(1);
|
||||
assert_eq!(input.get(), 1);
|
||||
println!("read memo 1");
|
||||
assert_eq!(first_memo.get(), true);
|
||||
println!("read memo 2");
|
||||
assert_eq!(second_memo.get(), true);
|
||||
|
||||
// this time, we don't read the memo
|
||||
println!("\nupdate to 2");
|
||||
input.set(2);
|
||||
assert_eq!(input.get(), 2);
|
||||
println!("read memo 1");
|
||||
assert_eq!(first_memo.get(), false);
|
||||
|
||||
println!("\nupdate to 3");
|
||||
input.set(3);
|
||||
assert_eq!(input.get(), 3);
|
||||
println!("read memo 1");
|
||||
assert_eq!(first_memo.get(), false);
|
||||
println!("read memo 2");
|
||||
assert_eq!(second_memo.get(), false);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use reactive_graph::{
|
||||
owner::Owner,
|
||||
signal::{arc_signal, signal, ArcRwSignal, RwSignal},
|
||||
traits::{
|
||||
Dispose, Get, GetUntracked, IntoInner, Read, Set, Update,
|
||||
UpdateUntracked, With, WithUntracked, Write,
|
||||
Get, GetUntracked, Read, Set, Update, UpdateUntracked, With,
|
||||
WithUntracked, Write,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -108,35 +108,3 @@ fn update_signal() {
|
||||
set_a.set(4);
|
||||
assert_eq!(a.get(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_inner_signal() {
|
||||
let owner = Owner::new();
|
||||
owner.set();
|
||||
|
||||
let rw_signal = RwSignal::new(1);
|
||||
assert_eq!(rw_signal.get(), 1);
|
||||
assert_eq!(rw_signal.into_inner(), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_inner_arc_signal() {
|
||||
let owner = Owner::new();
|
||||
owner.set();
|
||||
|
||||
let (a, b) = arc_signal(2);
|
||||
assert_eq!(a.get(), 2);
|
||||
std::mem::drop(b);
|
||||
assert_eq!(a.into_inner(), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn into_inner_non_arc_signal() {
|
||||
let owner = Owner::new();
|
||||
owner.set();
|
||||
|
||||
let (a, b) = signal(2);
|
||||
assert_eq!(a.get(), 2);
|
||||
b.dispose();
|
||||
assert_eq!(a.into_inner(), Some(2));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "reactive_stores"
|
||||
version = "0.1.1"
|
||||
version = "0.1.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
@@ -23,6 +23,3 @@ tokio = { version = "1.41", features = ["rt-multi-thread", "macros"] }
|
||||
tokio-test = { version = "0.4.4" }
|
||||
any_spawner = { workspace = true, features = ["futures-executor", "tokio"] }
|
||||
reactive_graph = { workspace = true, features = ["effects"] }
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
|
||||
@@ -26,7 +26,7 @@ pub struct ArcField<T>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
path: StorePath,
|
||||
trigger: StoreFieldTrigger,
|
||||
@@ -116,7 +116,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: Store<T, S>) -> Self {
|
||||
ArcField {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
path: value.path().into_iter().collect(),
|
||||
trigger: value.get_trigger(value.path().into_iter().collect()),
|
||||
@@ -136,7 +136,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: ArcStore<T>) -> Self {
|
||||
ArcField {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
path: value.path().into_iter().collect(),
|
||||
trigger: value.get_trigger(value.path().into_iter().collect()),
|
||||
@@ -174,7 +174,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: Subfield<Inner, Prev, T>) -> Self {
|
||||
ArcField {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
path: value.path().into_iter().collect(),
|
||||
trigger: value.get_trigger(value.path().into_iter().collect()),
|
||||
@@ -212,7 +212,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: AtIndex<Inner, Prev>) -> Self {
|
||||
ArcField {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
path: value.path().into_iter().collect(),
|
||||
trigger: value.get_trigger(value.path().into_iter().collect()),
|
||||
@@ -254,7 +254,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: AtKeyed<Inner, Prev, K, T>) -> Self {
|
||||
ArcField {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
path: value.path().into_iter().collect(),
|
||||
trigger: value.get_trigger(value.path().into_iter().collect()),
|
||||
@@ -285,7 +285,7 @@ where
|
||||
impl<T> Clone for ArcField<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
path: self.path.clone(),
|
||||
trigger: self.trigger.clone(),
|
||||
@@ -300,11 +300,11 @@ impl<T> Clone for ArcField<T> {
|
||||
|
||||
impl<T> DefinedAt for ArcField<T> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct Field<T, S = SyncStorage>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: ArenaItem<ArcField<T>, S>,
|
||||
}
|
||||
@@ -75,7 +75,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: Store<T, S>) -> Self {
|
||||
Field {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value.into()),
|
||||
}
|
||||
@@ -90,7 +90,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: ArcStore<T>) -> Self {
|
||||
Field {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value.into()),
|
||||
}
|
||||
@@ -108,7 +108,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: Subfield<Inner, Prev, T>) -> Self {
|
||||
Field {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value.into()),
|
||||
}
|
||||
@@ -126,7 +126,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: AtIndex<Inner, Prev>) -> Self {
|
||||
Field {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value.into()),
|
||||
}
|
||||
@@ -149,7 +149,7 @@ where
|
||||
#[track_caller]
|
||||
fn from(value: AtKeyed<Inner, Prev, K, T>) -> Self {
|
||||
Field {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(value.into()),
|
||||
}
|
||||
@@ -166,11 +166,11 @@ impl<T, S> Copy for Field<T, S> {}
|
||||
|
||||
impl<T, S> DefinedAt for Field<T, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use std::{
|
||||
/// Provides access to the data at some index in another collection.
|
||||
#[derive(Debug)]
|
||||
pub struct AtIndex<Inner, Prev> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: Inner,
|
||||
index: usize,
|
||||
@@ -36,7 +36,7 @@ where
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
inner: self.inner.clone(),
|
||||
index: self.index,
|
||||
@@ -52,7 +52,7 @@ impl<Inner, Prev> AtIndex<Inner, Prev> {
|
||||
#[track_caller]
|
||||
pub fn new(inner: Inner, index: usize) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner,
|
||||
index,
|
||||
@@ -115,11 +115,11 @@ where
|
||||
Inner: StoreField<Value = Prev>,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ pub struct KeyedSubfield<Inner, Prev, K, T>
|
||||
where
|
||||
for<'a> &'a T: IntoIterator,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
path_segment: StorePathSegment,
|
||||
inner: Inner,
|
||||
@@ -44,7 +44,7 @@ where
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
path_segment: self.path_segment,
|
||||
inner: self.inner.clone(),
|
||||
@@ -76,7 +76,7 @@ where
|
||||
write: fn(&mut Prev) -> &mut T,
|
||||
) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner,
|
||||
path_segment,
|
||||
@@ -254,11 +254,11 @@ where
|
||||
Inner: StoreField<Value = Prev>,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -356,7 +356,7 @@ pub struct AtKeyed<Inner, Prev, K, T>
|
||||
where
|
||||
for<'a> &'a T: IntoIterator,
|
||||
{
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: KeyedSubfield<Inner, Prev, K, T>,
|
||||
key: K,
|
||||
@@ -370,7 +370,7 @@ where
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
inner: self.inner.clone(),
|
||||
key: self.key.clone(),
|
||||
@@ -394,7 +394,7 @@ where
|
||||
#[track_caller]
|
||||
pub fn new(inner: KeyedSubfield<Inner, Prev, K, T>, key: K) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner,
|
||||
key,
|
||||
@@ -511,11 +511,11 @@ where
|
||||
for<'a> &'a T: IntoIterator,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -623,15 +623,10 @@ where
|
||||
.keys()
|
||||
.expect("updating keys on a store with no keys");
|
||||
|
||||
// generating the latest keys out here means that if we have
|
||||
// nested keyed fields, the second field will not try to take a
|
||||
// read-lock on the key map to get the field while the first field
|
||||
// is still holding the write-lock in the closure below
|
||||
let latest = self.latest_keys();
|
||||
keys.with_field_keys(
|
||||
inner_path,
|
||||
|keys| {
|
||||
keys.update(latest);
|
||||
keys.update(self.latest_keys());
|
||||
},
|
||||
|| self.latest_keys(),
|
||||
);
|
||||
|
||||
@@ -315,7 +315,7 @@ impl KeyMap {
|
||||
/// This adds a getter method for each field to `Store<T>`, which allow accessing reactive versions
|
||||
/// of each individual field of the struct.
|
||||
pub struct ArcStore<T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
pub(crate) value: Arc<RwLock<T>>,
|
||||
signals: Arc<RwLock<TriggerMap>>,
|
||||
@@ -326,7 +326,7 @@ impl<T> ArcStore<T> {
|
||||
/// Creates a new store from the initial value.
|
||||
pub fn new(value: T) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
value: Arc::new(RwLock::new(value)),
|
||||
signals: Default::default(),
|
||||
@@ -338,7 +338,7 @@ impl<T> ArcStore<T> {
|
||||
impl<T: Debug> Debug for ArcStore<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut f = f.debug_struct("ArcStore");
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let f = f.field("defined_at", &self.defined_at);
|
||||
f.field("value", &self.value)
|
||||
.field("signals", &self.signals)
|
||||
@@ -349,7 +349,7 @@ impl<T: Debug> Debug for ArcStore<T> {
|
||||
impl<T> Clone for ArcStore<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
value: Arc::clone(&self.value),
|
||||
signals: Arc::clone(&self.signals),
|
||||
@@ -360,11 +360,11 @@ impl<T> Clone for ArcStore<T> {
|
||||
|
||||
impl<T> DefinedAt for ArcStore<T> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
@@ -433,7 +433,7 @@ impl<T: 'static> Notify for ArcStore<T> {
|
||||
/// This follows the same ownership rules as arena-allocated types like
|
||||
/// [`RwSignal`](reactive_graph::signal::RwSignal).
|
||||
pub struct Store<T, S = SyncStorage> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
inner: ArenaItem<ArcStore<T>, S>,
|
||||
}
|
||||
@@ -445,7 +445,7 @@ where
|
||||
/// Creates a new store with the initial value.
|
||||
pub fn new(value: T) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcStore::new(value)),
|
||||
}
|
||||
@@ -461,7 +461,7 @@ where
|
||||
/// This pins the value to the current thread. Accessing it from any other thread will panic.
|
||||
pub fn new_local(value: T) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner: ArenaItem::new_with_storage(ArcStore::new(value)),
|
||||
}
|
||||
@@ -474,7 +474,7 @@ where
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut f = f.debug_struct("Store");
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
let f = f.field("defined_at", &self.defined_at);
|
||||
f.field("inner", &self.inner).finish()
|
||||
}
|
||||
@@ -490,11 +490,11 @@ impl<T, S> Copy for Store<T, S> {}
|
||||
|
||||
impl<T, S> DefinedAt for Store<T, S> {
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ patch_primitives! {
|
||||
Arc<str>,
|
||||
Rc<str>,
|
||||
Cow<'_, str>,
|
||||
usize,
|
||||
u8,
|
||||
u16,
|
||||
u32,
|
||||
|
||||
@@ -18,7 +18,7 @@ use std::{iter, marker::PhantomData, ops::DerefMut, panic::Location};
|
||||
/// Accesses a single field of a reactive structure.
|
||||
#[derive(Debug)]
|
||||
pub struct Subfield<Inner, Prev, T> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: &'static Location<'static>,
|
||||
path_segment: StorePathSegment,
|
||||
inner: Inner,
|
||||
@@ -33,7 +33,7 @@ where
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
path_segment: self.path_segment,
|
||||
inner: self.inner.clone(),
|
||||
@@ -56,7 +56,7 @@ impl<Inner, Prev, T> Subfield<Inner, Prev, T> {
|
||||
write: fn(&mut Prev) -> &mut T,
|
||||
) -> Self {
|
||||
Self {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: Location::caller(),
|
||||
inner,
|
||||
path_segment,
|
||||
@@ -119,11 +119,11 @@ where
|
||||
Inner: StoreField<Value = Prev>,
|
||||
{
|
||||
fn defined_at(&self) -> Option<&'static Location<'static>> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
Some(self.defined_at)
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_router"
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
authors = ["Greg Johnston", "Ben Wishovich"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
|
||||
@@ -92,9 +92,6 @@ pub fn A<H>(
|
||||
/// a trailing slash.
|
||||
#[prop(optional)]
|
||||
strict_trailing_slash: bool,
|
||||
/// If `true`, the router will scroll to the top of the window at the end of navigation. Defaults to `true`.
|
||||
#[prop(default = true)]
|
||||
scroll: bool,
|
||||
/// The nodes or elements to be shown inside the link.
|
||||
children: Children,
|
||||
) -> impl IntoView
|
||||
@@ -107,7 +104,6 @@ where
|
||||
exact: bool,
|
||||
children: Children,
|
||||
strict_trailing_slash: bool,
|
||||
scroll: bool,
|
||||
) -> impl IntoView {
|
||||
let RouterContext { current_url, .. } =
|
||||
use_context().expect("tried to use <A/> outside a <Router/>.");
|
||||
@@ -133,7 +129,6 @@ where
|
||||
href=move || href.get().unwrap_or_default()
|
||||
target=target
|
||||
aria-current=move || if is_active() { Some("page") } else { None }
|
||||
data-noscroll=!scroll
|
||||
>
|
||||
|
||||
{children()}
|
||||
@@ -142,7 +137,7 @@ where
|
||||
}
|
||||
|
||||
let href = use_resolved_path(move || href.to_href()());
|
||||
inner(href, target, exact, children, strict_trailing_slash, scroll)
|
||||
inner(href, target, exact, children, strict_trailing_slash)
|
||||
}
|
||||
|
||||
// Test if `href` is active for `location`. Assumes _both_ `href` and `location` begin with a `'/'`.
|
||||
|
||||
@@ -359,8 +359,7 @@ where
|
||||
let change = LocationChange {
|
||||
value: to,
|
||||
replace,
|
||||
scroll: !a.has_attribute("noscroll")
|
||||
&& !a.has_attribute("data-noscroll"),
|
||||
scroll: true,
|
||||
state: State::new(state),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "leptos_router_macro"
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
authors = ["Greg Johnston", "Ben Wishovich"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
@@ -19,6 +19,3 @@ quote = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
leptos_router = { path = "../router" }
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
2
server_fn/Cargo.lock
generated
2
server_fn/Cargo.lock
generated
@@ -1447,7 +1447,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "radium"
|
||||
version = "0.7.1"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
|
||||
|
||||
|
||||
@@ -229,6 +229,3 @@ skip_feature_sets = [
|
||||
"rkyv",
|
||||
],
|
||||
]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{error::ServerFnError, request::Req};
|
||||
use actix_web::{web::Payload, HttpRequest};
|
||||
use bytes::Bytes;
|
||||
use futures::{Stream, StreamExt};
|
||||
use futures::Stream;
|
||||
use send_wrapper::SendWrapper;
|
||||
use std::{borrow::Cow, future::Future};
|
||||
|
||||
@@ -91,10 +91,6 @@ where
|
||||
impl Stream<Item = Result<Bytes, ServerFnError>> + Send,
|
||||
ServerFnError<CustErr>,
|
||||
> {
|
||||
let payload = self.0.take().1;
|
||||
let stream = payload.map(|res| {
|
||||
res.map_err(|e| ServerFnError::Deserialization(e.to_string()))
|
||||
});
|
||||
Ok(SendWrapper::new(stream))
|
||||
Ok(futures::stream::once(async { todo!() }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,20 +188,6 @@ pub fn server_macro_impl(
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
// we need to apply the same sort of Actix SendWrapper workaround here
|
||||
// that we do for the body of the function provided in the trait (see below)
|
||||
if cfg!(feature = "actix") {
|
||||
let block = body.block.to_token_stream();
|
||||
body.block = quote! {
|
||||
{
|
||||
#server_fn_path::actix::SendWrapper::new(async move {
|
||||
#block
|
||||
})
|
||||
.await
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let dummy = body.to_dummy_output();
|
||||
let dummy_name = body.to_dummy_ident();
|
||||
let args = syn::parse::<ServerFnArgs>(args.into())?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tachys"
|
||||
version = "0.1.1"
|
||||
version = "0.1.0"
|
||||
authors = ["Greg Johnston"]
|
||||
license = "MIT"
|
||||
readme = "../README.md"
|
||||
@@ -196,6 +196,3 @@ skip_feature_sets = [
|
||||
"delegation",
|
||||
],
|
||||
]
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(leptos_debuginfo)'] }
|
||||
|
||||
@@ -9,7 +9,7 @@ where
|
||||
E: AsRef<str>,
|
||||
{
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
tag: Custom(tag),
|
||||
attributes: (),
|
||||
|
||||
@@ -25,7 +25,7 @@ macro_rules! html_element_inner {
|
||||
|
||||
{
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
tag: $struct_name,
|
||||
attributes: (),
|
||||
@@ -57,14 +57,14 @@ macro_rules! html_element_inner {
|
||||
<At as NextTuple>::Output<Attr<$crate::html::attribute::[<$attr:camel>], V>>: Attribute,
|
||||
{
|
||||
let HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
attributes
|
||||
} = self;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
@@ -132,7 +132,7 @@ macro_rules! html_self_closing_elements {
|
||||
|
||||
{
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
attributes: (),
|
||||
children: (),
|
||||
@@ -162,14 +162,14 @@ macro_rules! html_self_closing_elements {
|
||||
<At as NextTuple>::Output<Attr<$crate::html::attribute::[<$attr:camel>], V>>: Attribute,
|
||||
{
|
||||
let HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
attributes,
|
||||
} = self;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
@@ -340,7 +340,7 @@ html_elements! {
|
||||
/// The `<nav>` HTML element represents a section of a page whose purpose is to provide navigation links, either within the current document or to other documents. Common examples of navigation sections are menus, tables of contents, and indexes.
|
||||
nav HtmlElement [] true,
|
||||
/// The `<noscript>` HTML element defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser.
|
||||
noscript HtmlElement [] false,
|
||||
noscript HtmlElement [] true,
|
||||
/// The `<object>` HTML element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin.
|
||||
object HtmlObjectElement [data, form, height, name, r#type, usemap, width] true,
|
||||
/// The `<ol>` HTML element represents an ordered list of items — typically rendered as a numbered list.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
use crate::hydration::set_currently_hydrating;
|
||||
use crate::{
|
||||
html::attribute::Attribute,
|
||||
@@ -26,13 +26,13 @@ pub use custom::*;
|
||||
pub use element_ext::*;
|
||||
pub use elements::*;
|
||||
pub use inner_html::*;
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
use std::panic::Location;
|
||||
|
||||
/// The typed representation of an HTML element.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct HtmlElement<E, At, Ch> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) defined_at: &'static Location<'static>,
|
||||
pub(crate) tag: E,
|
||||
pub(crate) attributes: At,
|
||||
@@ -42,7 +42,7 @@ pub struct HtmlElement<E, At, Ch> {
|
||||
impl<E: Clone, At: Clone, Ch: Clone> Clone for HtmlElement<E, At, Ch> {
|
||||
fn clone(&self) -> Self {
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
tag: self.tag.clone(),
|
||||
attributes: self.attributes.clone(),
|
||||
@@ -82,14 +82,14 @@ where
|
||||
|
||||
fn child(self, child: NewChild) -> Self::Output {
|
||||
let HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
attributes,
|
||||
children,
|
||||
} = self;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
attributes,
|
||||
@@ -112,14 +112,14 @@ where
|
||||
attr: NewAttr,
|
||||
) -> Self::Output<NewAttr> {
|
||||
let HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
attributes,
|
||||
children,
|
||||
} = self;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
attributes: attributes.add_any_attr(attr),
|
||||
@@ -242,7 +242,7 @@ where
|
||||
let (attributes, children) =
|
||||
join(self.attributes.resolve(), self.children.resolve()).await;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: self.defined_at,
|
||||
tag: self.tag,
|
||||
attributes,
|
||||
@@ -350,7 +350,7 @@ where
|
||||
cursor: &Cursor,
|
||||
position: &PositionState,
|
||||
) -> Self::State {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
set_currently_hydrating(Some(self.defined_at));
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@ use self::attribute::Attribute;
|
||||
use crate::{
|
||||
hydration::Cursor,
|
||||
no_attrs,
|
||||
prelude::{AddAnyAttr, Mountable},
|
||||
renderer::{
|
||||
dom::{Element, Node},
|
||||
CastFrom, Rndr,
|
||||
},
|
||||
prelude::AddAnyAttr,
|
||||
renderer::{CastFrom, Rndr},
|
||||
view::{Position, PositionState, Render, RenderHtml},
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
@@ -93,41 +90,14 @@ impl InertElement {
|
||||
}
|
||||
}
|
||||
|
||||
/// Retained view state for [`InertElement`].
|
||||
pub struct InertElementState(Cow<'static, str>, Element);
|
||||
|
||||
impl Mountable for InertElementState {
|
||||
fn unmount(&mut self) {
|
||||
self.1.unmount();
|
||||
}
|
||||
|
||||
fn mount(&mut self, parent: &Element, marker: Option<&Node>) {
|
||||
self.1.mount(parent, marker)
|
||||
}
|
||||
|
||||
fn insert_before_this(&self, child: &mut dyn Mountable) -> bool {
|
||||
self.1.insert_before_this(child)
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for InertElement {
|
||||
type State = InertElementState;
|
||||
type State = crate::renderer::types::Element;
|
||||
|
||||
fn build(self) -> Self::State {
|
||||
let el = Rndr::create_element_from_html(&self.html);
|
||||
InertElementState(self.html, el)
|
||||
Rndr::create_element_from_html(&self.html)
|
||||
}
|
||||
|
||||
fn rebuild(self, state: &mut Self::State) {
|
||||
let InertElementState(prev, el) = state;
|
||||
if &self.html != prev {
|
||||
let mut new_el = Rndr::create_element_from_html(&self.html);
|
||||
el.insert_before_this(&mut new_el);
|
||||
el.unmount();
|
||||
*el = new_el;
|
||||
*prev = self.html;
|
||||
}
|
||||
}
|
||||
fn rebuild(self, _state: &mut Self::State) {}
|
||||
}
|
||||
|
||||
impl AddAnyAttr for InertElement {
|
||||
@@ -187,6 +157,6 @@ impl RenderHtml for InertElement {
|
||||
let el = crate::renderer::types::Element::cast_from(cursor.current())
|
||||
.unwrap();
|
||||
position.set(Position::NextChild);
|
||||
InertElementState(self.html, el)
|
||||
el
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
renderer::{CastFrom, Rndr},
|
||||
view::{Position, PositionState},
|
||||
};
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
use std::cell::Cell;
|
||||
use std::{cell::RefCell, panic::Location, rc::Rc};
|
||||
use web_sys::{Comment, Element, Node, Text};
|
||||
@@ -103,7 +103,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
thread_local! {
|
||||
static CURRENTLY_HYDRATING: Cell<Option<&'static Location<'static>>> = const { Cell::new(None) };
|
||||
}
|
||||
@@ -111,23 +111,23 @@ thread_local! {
|
||||
pub(crate) fn set_currently_hydrating(
|
||||
location: Option<&'static Location<'static>>,
|
||||
) {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
CURRENTLY_HYDRATING.set(location);
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
_ = location;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn failed_to_cast_element(tag_name: &str, node: Node) -> Element {
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
_ = node;
|
||||
unreachable!();
|
||||
}
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let hydrating = CURRENTLY_HYDRATING
|
||||
.take()
|
||||
@@ -154,12 +154,12 @@ pub(crate) fn failed_to_cast_element(tag_name: &str, node: Node) -> Element {
|
||||
}
|
||||
|
||||
pub(crate) fn failed_to_cast_marker_node(node: Node) -> Comment {
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
_ = node;
|
||||
unreachable!();
|
||||
}
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let hydrating = CURRENTLY_HYDRATING
|
||||
.take()
|
||||
@@ -186,12 +186,12 @@ pub(crate) fn failed_to_cast_marker_node(node: Node) -> Comment {
|
||||
}
|
||||
|
||||
pub(crate) fn failed_to_cast_text_node(node: Node) -> Text {
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
_ = node;
|
||||
unreachable!();
|
||||
}
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let hydrating = CURRENTLY_HYDRATING
|
||||
.take()
|
||||
|
||||
@@ -87,7 +87,7 @@ impl<T> UnwrapOrDebug for Result<T, JsValue> {
|
||||
|
||||
#[track_caller]
|
||||
fn or_debug(self, el: &Node, name: &'static str) {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if let Err(err) = self {
|
||||
let location = std::panic::Location::caller();
|
||||
@@ -101,7 +101,7 @@ impl<T> UnwrapOrDebug for Result<T, JsValue> {
|
||||
);
|
||||
}
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
_ = self;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ impl<T> UnwrapOrDebug for Result<T, JsValue> {
|
||||
el: &Node,
|
||||
name: &'static str,
|
||||
) -> Option<Self::Output> {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if let Err(err) = &self {
|
||||
let location = std::panic::Location::caller();
|
||||
@@ -128,7 +128,7 @@ impl<T> UnwrapOrDebug for Result<T, JsValue> {
|
||||
}
|
||||
self.ok()
|
||||
}
|
||||
#[cfg(not(any(debug_assertions, leptos_debuginfo)))]
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
self.ok()
|
||||
}
|
||||
@@ -139,7 +139,7 @@ impl<T> UnwrapOrDebug for Result<T, JsValue> {
|
||||
#[macro_export]
|
||||
macro_rules! or_debug {
|
||||
($action:expr, $el:expr, $label:literal) => {
|
||||
if cfg!(any(debug_assertions, leptos_debuginfo)) {
|
||||
if cfg!(debug_assertions) {
|
||||
$crate::UnwrapOrDebug::or_debug($action, $el, $label);
|
||||
} else {
|
||||
_ = $action;
|
||||
@@ -151,7 +151,7 @@ macro_rules! or_debug {
|
||||
#[macro_export]
|
||||
macro_rules! ok_or_debug {
|
||||
($action:expr, $el:expr, $label:literal) => {
|
||||
if cfg!(any(debug_assertions, leptos_debuginfo)) {
|
||||
if cfg!(debug_assertions) {
|
||||
$crate::UnwrapOrDebug::ok_or_debug($action, $el, $label)
|
||||
} else {
|
||||
$action.ok()
|
||||
|
||||
@@ -23,14 +23,14 @@ macro_rules! mathml_global {
|
||||
<At as NextTuple>::Output<Attr<$crate::html::attribute::[<$attr:camel>], V>>: Attribute,
|
||||
{
|
||||
let HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
attributes
|
||||
} = self;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
@@ -53,7 +53,7 @@ macro_rules! mathml_elements {
|
||||
|
||||
{
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
tag: [<$tag:camel>],
|
||||
attributes: (),
|
||||
@@ -93,14 +93,14 @@ macro_rules! mathml_elements {
|
||||
<At as NextTuple>::Output<Attr<$crate::html::attribute::[<$attr:camel>], V>>: Attribute,
|
||||
{
|
||||
let HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
attributes
|
||||
} = self;
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at,
|
||||
tag,
|
||||
children,
|
||||
|
||||
@@ -9,15 +9,13 @@ use crate::{
|
||||
renderer::{types::Element, RemoveEventHandler},
|
||||
view::{Position, ToTemplate},
|
||||
};
|
||||
#[cfg(feature = "reactive_stores")]
|
||||
use reactive_graph::owner::Storage;
|
||||
use reactive_graph::{
|
||||
signal::{ReadSignal, RwSignal, WriteSignal},
|
||||
traits::{Get, Update},
|
||||
wrappers::read::Signal,
|
||||
};
|
||||
#[cfg(feature = "reactive_stores")]
|
||||
use reactive_stores::{ArcField, Field, KeyedSubfield, Subfield};
|
||||
use reactive_stores::{KeyedSubfield, Subfield};
|
||||
use send_wrapper::SendWrapper;
|
||||
use wasm_bindgen::JsValue;
|
||||
|
||||
@@ -360,21 +358,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "reactive_stores")]
|
||||
impl<T, S> IntoSplitSignal for Field<T, S>
|
||||
where
|
||||
Self: Get<Value = T> + Update<Value = T> + Clone,
|
||||
S: Storage<ArcField<T>>,
|
||||
{
|
||||
type Value = T;
|
||||
type Read = Self;
|
||||
type Write = Self;
|
||||
|
||||
fn into_split_signal(self) -> (Self::Read, Self::Write) {
|
||||
(self, self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "reactive_stores")]
|
||||
impl<Inner, Prev, K, T> IntoSplitSignal for KeyedSubfield<Inner, Prev, K, T>
|
||||
where
|
||||
|
||||
@@ -444,8 +444,7 @@ impl Dom {
|
||||
// TODO can be optimized to cache HTML strings or cache <template>?
|
||||
let tpl = document().create_element("template").unwrap();
|
||||
tpl.set_inner_html(html);
|
||||
let tpl = Self::clone_template(tpl.unchecked_ref());
|
||||
tpl.first_element_child().unwrap_or(tpl)
|
||||
Self::clone_template(tpl.unchecked_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ macro_rules! svg_elements {
|
||||
where
|
||||
{
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
tag: [<$tag:camel>],
|
||||
attributes: (),
|
||||
@@ -49,7 +49,7 @@ macro_rules! svg_elements {
|
||||
<At as NextTuple<Attr<$crate::html::attribute::[<$attr:camel>], V>>>::Output: Attribute,
|
||||
{
|
||||
let HtmlElement { tag, children, attributes,
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at
|
||||
} = self;
|
||||
HtmlElement {
|
||||
@@ -57,7 +57,7 @@ macro_rules! svg_elements {
|
||||
|
||||
children,
|
||||
attributes: attributes.next_tuple($crate::html::attribute::$attr(value)),
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ svg_elements![
|
||||
pub fn r#use() -> HtmlElement<Use, (), ()>
|
||||
where {
|
||||
HtmlElement {
|
||||
#[cfg(any(debug_assertions, leptos_debuginfo))]
|
||||
#[cfg(debug_assertions)]
|
||||
defined_at: std::panic::Location::caller(),
|
||||
tag: Use,
|
||||
attributes: (),
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::{
|
||||
use crate::{
|
||||
html::attribute::{Attribute, AttributeKey, AttributeValue, NextAttribute},
|
||||
hydration::Cursor,
|
||||
renderer::{CastFrom, Rndr},
|
||||
renderer::Rndr,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -180,11 +180,8 @@ impl<const V: &'static str> RenderHtml for Static<V> {
|
||||
if matches!(position, Position::NextChildAfterText) {
|
||||
buf.push_str("<!>")
|
||||
}
|
||||
if V.is_empty() && escape {
|
||||
buf.push(' ');
|
||||
} else if escape {
|
||||
let escaped = html_escape::encode_text(V);
|
||||
buf.push_str(&escaped);
|
||||
if escape {
|
||||
buf.push_str(&html_escape::encode_text(V));
|
||||
} else {
|
||||
buf.push_str(V);
|
||||
}
|
||||
@@ -201,18 +198,13 @@ impl<const V: &'static str> RenderHtml for Static<V> {
|
||||
} else {
|
||||
cursor.sibling();
|
||||
}
|
||||
|
||||
// separating placeholder marker comes before text node
|
||||
if matches!(position.get(), Position::NextChildAfterText) {
|
||||
cursor.sibling();
|
||||
}
|
||||
position.set(Position::NextChildAfterText);
|
||||
|
||||
let node = cursor.current();
|
||||
let node = crate::renderer::types::Text::cast_from(node.clone())
|
||||
.unwrap_or_else(|| {
|
||||
crate::hydration::failed_to_cast_text_node(node)
|
||||
});
|
||||
Some(node)
|
||||
// no view state is created when hydrating, because this is static
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user