From f2f52b2533d668f489df11deb473364e3b3a2b73 Mon Sep 17 00:00:00 2001 From: jquesada2016 <54370171+jquesada2016@users.noreply.github.com> Date: Sat, 18 Feb 2023 06:30:03 -0600 Subject: [PATCH] change: move signal method implementations into traits in signal prelude (#490) --- .../hackernews_axum/src/error_template.rs | 32 +- examples/todomvc/src/storage.rs | 34 +- integrations/actix/src/lib.rs | 8 +- integrations/axum/src/lib.rs | 4 +- leptos/src/error_boundary.rs | 4 +- leptos/src/show.rs | 2 +- leptos/src/suspense.rs | 2 + leptos/tests/ssr.rs | 4 +- leptos_dom/src/components/errors.rs | 2 +- leptos_dom/src/node_ref.rs | 4 +- leptos_macro/src/lib.rs | 2 +- leptos_reactive/src/lib.rs | 42 +- leptos_reactive/src/memo.rs | 233 +-- leptos_reactive/src/resource.rs | 4 +- leptos_reactive/src/runtime.rs | 7 +- leptos_reactive/src/selector.rs | 3 +- leptos_reactive/src/signal.rs | 1361 ++++++++++++----- leptos_reactive/src/signal_wrappers_read.rs | 662 ++++---- leptos_reactive/src/signal_wrappers_write.rs | 71 +- leptos_reactive/src/slice.rs | 1 + leptos_reactive/src/stored_value.rs | 285 +++- leptos_reactive/src/suspense.rs | 5 +- leptos_reactive/tests/untracked.rs | 2 +- leptos_server/src/action.rs | 20 +- leptos_server/src/multi_action.rs | 26 +- router/src/components/redirect.rs | 4 +- router/src/components/route.rs | 2 +- router/src/hooks.rs | 2 +- 28 files changed, 1832 insertions(+), 996 deletions(-) diff --git a/examples/hackernews_axum/src/error_template.rs b/examples/hackernews_axum/src/error_template.rs index a8b85d5..57655d3 100644 --- a/examples/hackernews_axum/src/error_template.rs +++ b/examples/hackernews_axum/src/error_template.rs @@ -1,4 +1,7 @@ -use leptos::{view, Errors, For, ForProps, IntoView, RwSignal, Scope, View}; +use leptos::{ + signal_prelude::*, view, Errors, For, ForProps, IntoView, RwSignal, Scope, + View, +}; // A basic function to display errors served by the error boundaries. Feel free to do more complicated things // here than just displaying them @@ -6,21 +9,22 @@ pub fn error_template(cx: Scope, errors: Option>) -> View { let Some(errors) = errors else { panic!("No Errors found and we expected errors!"); }; + view! {cx, -

"Errors"

- "Error: " {error_string}

+

"Errors"

+ "Error: " {error_string}

+ } } - } /> } .into_view(cx) diff --git a/examples/todomvc/src/storage.rs b/examples/todomvc/src/storage.rs index 3bb54f9..8554da7 100644 --- a/examples/todomvc/src/storage.rs +++ b/examples/todomvc/src/storage.rs @@ -1,27 +1,33 @@ use crate::Todo; -use leptos::Scope; -use serde::{Deserialize, Serialize}; +use leptos::{ + signal_prelude::*, + Scope, +}; +use serde::{ + Deserialize, + Serialize, +}; use uuid::Uuid; #[derive(Serialize, Deserialize)] pub struct TodoSerialized { - pub id: Uuid, - pub title: String, - pub completed: bool, + pub id: Uuid, + pub title: String, + pub completed: bool, } impl TodoSerialized { - pub fn into_todo(self, cx: Scope) -> Todo { - Todo::new_with_completed(cx, self.id, self.title, self.completed) - } + pub fn into_todo(self, cx: Scope) -> Todo { + Todo::new_with_completed(cx, self.id, self.title, self.completed) + } } impl From<&Todo> for TodoSerialized { - fn from(todo: &Todo) -> Self { - Self { - id: todo.id, - title: todo.title.get(), - completed: todo.completed.get(), - } + fn from(todo: &Todo) -> Self { + Self { + id: todo.id, + title: todo.title.get(), + completed: todo.completed.get(), } + } } diff --git a/integrations/actix/src/lib.rs b/integrations/actix/src/lib.rs index 26e4d60..a8836cc 100644 --- a/integrations/actix/src/lib.rs +++ b/integrations/actix/src/lib.rs @@ -282,8 +282,8 @@ pub fn handle_server_fns_with_context( /// The provides a [MetaContext] and a [RouterIntegrationContext] to app’s context before /// rendering it, and includes any meta tags injected using [leptos_meta]. /// -/// The HTML stream is rendered using [render_to_stream], and includes everything described in -/// the documentation for that function. +/// The HTML stream is rendered using [render_to_stream](leptos::ssr::render_to_stream), and +/// includes everything described in the documentation for that function. /// /// This can then be set up at an appropriate route in your application: /// ``` @@ -602,8 +602,8 @@ where /// The provides a [MetaContext] and a [RouterIntegrationContext] to app’s context before /// rendering it, and includes any meta tags injected using [leptos_meta]. /// -/// The HTML stream is rendered using [render_to_stream], and includes everything described in -/// the documentation for that function. +/// The HTML stream is rendered using [render_to_stream](leptos::ssr::render_to_stream), and +/// includes everything described in the documentation for that function. /// /// This can then be set up at an appropriate route in your application: /// ``` diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index b18157f..9e67447 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -342,8 +342,8 @@ pub type PinnedHtmlStream = /// The provides a [MetaContext] and a [RouterIntegrationContext] to app’s context before /// rendering it, and includes any meta tags injected using [leptos_meta]. /// -/// The HTML stream is rendered using [render_to_stream], and includes everything described in -/// the documentation for that function. +/// The HTML stream is rendered using [render_to_stream](leptos::ssr::render_to_stream), and +/// includes everything described in the documentation for that function. /// /// This can then be set up at an appropriate route in your application: /// ``` diff --git a/leptos/src/error_boundary.rs b/leptos/src/error_boundary.rs index 344119b..e9639bd 100644 --- a/leptos/src/error_boundary.rs +++ b/leptos/src/error_boundary.rs @@ -1,7 +1,9 @@ use crate::Children; use leptos_dom::{Errors, IntoView}; use leptos_macro::{component, view}; -use leptos_reactive::{create_rw_signal, provide_context, RwSignal, Scope}; +use leptos_reactive::{ + create_rw_signal, provide_context, signal_prelude::*, RwSignal, Scope, +}; /// When you render a `Result<_, _>` in your view, in the `Err` case it will /// render nothing, and search up through the view tree for an ``. diff --git a/leptos/src/show.rs b/leptos/src/show.rs index 2c0f830..7ee5026 100644 --- a/leptos/src/show.rs +++ b/leptos/src/show.rs @@ -1,6 +1,6 @@ use leptos::component; use leptos_dom::{Fragment, IntoView}; -use leptos_reactive::{create_memo, Scope}; +use leptos_reactive::{create_memo, signal_prelude::*, Scope}; /// A component that will show its children when the `when` condition is `true`, /// and show the fallback when it is `false`, without rerendering every time diff --git a/leptos/src/suspense.rs b/leptos/src/suspense.rs index f15baf6..dcf68a8 100644 --- a/leptos/src/suspense.rs +++ b/leptos/src/suspense.rs @@ -83,6 +83,8 @@ where fallback().into_view(cx) } } else { + use leptos_reactive::signal_prelude::*; + // run the child; we'll probably throw this away, but it will register resource reads let child = orig_child(cx).into_view(cx); let after_original_child = HydrationCtx::id(); diff --git a/leptos/tests/ssr.rs b/leptos/tests/ssr.rs index 6b66f59..138bc99 100644 --- a/leptos/tests/ssr.rs +++ b/leptos/tests/ssr.rs @@ -147,7 +147,7 @@ fn ssr_with_styles() { use leptos::*; _ = create_scope(create_runtime(), |cx| { - let (value, set_value) = create_signal(cx, 0); + let (_, set_value) = create_signal(cx, 0); let styles = "myclass"; let rendered = view! { cx, class = styles, @@ -170,7 +170,7 @@ fn ssr_option() { use leptos::*; _ = create_scope(create_runtime(), |cx| { - let (value, set_value) = create_signal(cx, 0); + let (_, _) = create_signal(cx, 0); let rendered = view! { cx,