From 40c1556f294f0f5edd58f0704a900f4e08de5872 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 12 May 2023 19:45:48 -0400 Subject: [PATCH] change: remove APIs that had been marked deprecated (#1037) --- integrations/actix/src/lib.rs | 140 --------------------- integrations/axum/src/lib.rs | 17 --- leptos/src/lib.rs | 2 - leptos_dom/src/helpers.rs | 63 +++------- leptos_dom/src/html.rs | 20 --- leptos_dom/src/node_ref.rs | 6 - leptos_reactive/src/signal.rs | 67 ---------- leptos_reactive/src/stored_value.rs | 185 ++-------------------------- 8 files changed, 30 insertions(+), 470 deletions(-) diff --git a/integrations/actix/src/lib.rs b/integrations/actix/src/lib.rs index 128c810cf..4021cc45e 100644 --- a/integrations/actix/src/lib.rs +++ b/integrations/actix/src/lib.rs @@ -697,103 +697,6 @@ where } } -/// Returns an Actix [Route](actix_web::Route) that listens for a `GET` request and tries -/// to route it using [leptos_router], serving an HTML stream of your application. -/// -/// 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](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: -/// ``` -/// use actix_web::{App, HttpServer}; -/// use leptos::*; -/// use leptos_actix::DataResponse; -/// use std::{env, net::SocketAddr}; -/// -/// #[component] -/// fn MyApp(cx: Scope, data: &'static str) -> impl IntoView { -/// view! { cx,
"Hello, world!"
} -/// } -/// -/// # if false { // don't actually try to run a server in a doctest... -/// #[actix_web::main] -/// async fn main() -> std::io::Result<()> { -/// let conf = get_configuration(Some("Cargo.toml")).await.unwrap(); -/// let addr = conf.leptos_options.site_addr.clone(); -/// HttpServer::new(move || { -/// let leptos_options = &conf.leptos_options; -/// -/// App::new() -/// // {tail:.*} passes the remainder of the URL as the route -/// // the actual routing will be handled by `leptos_router` -/// .route( -/// "/{tail:.*}", -/// leptos_actix::render_preloaded_data_app( -/// leptos_options.to_owned(), -/// |req| async move { -/// Ok(DataResponse::Data( -/// "async func that can preload data", -/// )) -/// }, -/// |cx, data| view! { cx, }, -/// ), -/// ) -/// }) -/// .bind(&addr)? -/// .run() -/// .await -/// } -/// # } -/// ``` -/// -/// ## Provided Context Types -/// This function always provides context values including the following types: -/// - [ResponseOptions] -/// - [HttpRequest](actix_web::HttpRequest) -/// - [MetaContext](leptos_meta::MetaContext) -/// - [RouterIntegrationContext](leptos_router::RouterIntegrationContext) -#[deprecated = "You can now use `render_app_async` with `create_resource` and \ - `` to achieve async rendering without manually \ - preloading data."] -pub fn render_preloaded_data_app( - options: LeptosOptions, - data_fn: impl Fn(HttpRequest) -> Fut + Clone + 'static, - app_fn: impl Fn(leptos::Scope, Data) -> IV + Clone + Send + 'static, -) -> Route -where - Data: 'static, - Fut: Future, actix_web::Error>>, - IV: IntoView + 'static, -{ - web::get().to(move |req: HttpRequest| { - let options = options.clone(); - let app_fn = app_fn.clone(); - let data_fn = data_fn.clone(); - let res_options = ResponseOptions::default(); - - async move { - let data = match data_fn(req.clone()).await { - Err(e) => return HttpResponse::from_error(e), - Ok(DataResponse::Response(r)) => return r.into(), - Ok(DataResponse::Data(d)) => d, - }; - - let app = { - let app_fn = app_fn.clone(); - let res_options = res_options.clone(); - move |cx| { - provide_contexts(cx, &req, res_options); - (app_fn)(cx, data).into_view(cx) - } - }; - - stream_app(&options, app, res_options, |_cx| {}, false).await - } - }) -} #[tracing::instrument(level = "trace", fields(error), skip_all)] fn provide_contexts( cx: leptos::Scope, @@ -1031,22 +934,6 @@ pub trait LeptosRoutes { where IV: IntoView + 'static; - #[deprecated = "You can now use `leptos_routes` and a `` - to achieve async rendering without manually preloading \ - data."] - fn leptos_preloaded_data_routes( - self, - options: LeptosOptions, - paths: Vec, - data_fn: impl Fn(HttpRequest) -> Fut + Clone + 'static, - app_fn: impl Fn(leptos::Scope, Data) -> IV + Clone + Send + 'static, - ) -> Self - where - Data: 'static, - Fut: Future, actix_web::Error>>, - IV: IntoView + 'static; - fn leptos_routes_with_context( self, options: LeptosOptions, @@ -1081,34 +968,7 @@ where { self.leptos_routes_with_context(options, paths, |_| {}, app_fn) } - #[tracing::instrument(level = "trace", fields(error), skip_all)] - fn leptos_preloaded_data_routes( - self, - options: LeptosOptions, - paths: Vec, - data_fn: impl Fn(HttpRequest) -> Fut + Clone + 'static, - app_fn: impl Fn(leptos::Scope, Data) -> IV + Clone + Send + 'static, - ) -> Self - where - Data: 'static, - Fut: Future, actix_web::Error>>, - IV: IntoView + 'static, - { - let mut router = self; - for path in paths.iter() { - router = router.route( - path, - #[allow(deprecated)] - render_preloaded_data_app( - options.clone(), - data_fn.clone(), - app_fn.clone(), - ), - ); - } - router - } #[tracing::instrument(level = "trace", fields(error), skip_all)] fn leptos_routes_with_context( self, diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index ce2b5edd9..83fef57c6 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -129,23 +129,6 @@ pub fn redirect(cx: leptos::Scope, path: &str) { } } -/// Decomposes an HTTP request into its parts, allowing you to read its headers -/// and other data without consuming the body. -#[deprecated(note = "Replaced with generate_request_and_parts() to allow for \ - putting LeptosRequest in the Context")] -pub async fn generate_request_parts(req: Request) -> RequestParts { - // provide request headers as context in server scope - let (parts, body) = req.into_parts(); - let body = body::to_bytes(body).await.unwrap_or_default(); - RequestParts { - method: parts.method, - uri: parts.uri, - headers: parts.headers, - version: parts.version, - body, - } -} - /// Decomposes an HTTP request into its parts, allowing you to read its headers /// and other data without consuming the body. Creates a new Request from the /// original parts for further processing diff --git a/leptos/src/lib.rs b/leptos/src/lib.rs index f43fbac58..4ea625a74 100644 --- a/leptos/src/lib.rs +++ b/leptos/src/lib.rs @@ -152,7 +152,6 @@ pub use leptos_config::{self, get_configuration, LeptosOptions}; pub mod ssr { pub use leptos_dom::{ssr::*, ssr_in_order::*}; } -#[allow(deprecated)] pub use leptos_dom::{ self, create_node_ref, debug_warn, document, error, ev, helpers::{ @@ -161,7 +160,6 @@ pub use leptos_dom::{ request_idle_callback, request_idle_callback_with_handle, set_interval, set_interval_with_handle, set_timeout, set_timeout_with_handle, window_event_listener, window_event_listener_untyped, - window_event_listener_with_precast, }, html, log, math, mount_to, mount_to_body, svg, warn, window, Attribute, Class, CollectView, Errors, Fragment, HtmlElement, IntoAttribute, diff --git a/leptos_dom/src/helpers.rs b/leptos_dom/src/helpers.rs index 73f317c94..e15c7c178 100644 --- a/leptos_dom/src/helpers.rs +++ b/leptos_dom/src/helpers.rs @@ -332,32 +332,8 @@ impl IntervalHandle { any(debug_assertions, features = "ssr"), instrument(level = "trace", skip_all, fields(duration = ?duration)) )] -#[deprecated = "use set_interval_with_handle() instead. In the future, \ - set_interval() will no longer return a handle, for consistency \ - with other timer helper functions."] -pub fn set_interval( - cb: impl Fn() + 'static, - duration: Duration, -) -> Result { - cfg_if::cfg_if! { - if #[cfg(debug_assertions)] { - let span = ::tracing::Span::current(); - let cb = move || { - leptos_reactive::SpecialNonReactiveZone::enter(); - let _guard = span.enter(); - cb(); - leptos_reactive::SpecialNonReactiveZone::exit(); - }; - } - } - - let cb = Closure::wrap(Box::new(cb) as Box).into_js_value(); - let handle = window() - .set_interval_with_callback_and_timeout_and_arguments_0( - cb.as_ref().unchecked_ref(), - duration.as_millis().try_into().unwrap_throw(), - )?; - Ok(IntervalHandle(handle)) +pub fn set_interval(cb: impl Fn() + 'static, duration: Duration) { + _ = set_interval_with_handle(cb, duration); } /// Repeatedly calls the given function, with a delay of the given duration between calls, @@ -402,24 +378,6 @@ pub fn set_interval_with_handle( si(Box::new(cb), duration) } -/// Adds an event listener to the `Window`. -#[cfg_attr( - any(debug_assertions, features = "ssr"), - instrument(level = "trace", skip_all, fields(event_name = %event_name)) -)] -#[inline(always)] -#[deprecated = "In the next release, `window_event_listener` will become \ - typed. You can switch now to `window_event_listener_untyped` \ - for the current behavior or use \ - `window_event_listener_with_precast`, which will become the \ - new`window_event_listener`."] -pub fn window_event_listener( - event_name: &str, - cb: impl Fn(web_sys::Event) + 'static, -) { - window_event_listener_untyped(event_name, cb) -} - /// Adds an event listener to the `Window`, typed as a generic `Event`. #[cfg_attr( debug_assertions, @@ -456,8 +414,21 @@ pub fn window_event_listener_untyped( } } -/// Creates a window event listener where the event in the callback is already appropriately cast. -pub fn window_event_listener_with_precast( +/// Creates a window event listener from a typed event. +/// ``` +/// use leptos::{leptos_dom::helpers::window_event_listener, *}; +/// +/// #[component] +/// fn App(cx: Scope) -> impl IntoView { +/// window_event_listener(ev::keypress, |ev| { +/// // ev is typed as KeyboardEvent automatically, +/// // so .code() can be called +/// let code = ev.code(); +/// log!("code = {code:?}"); +/// }) +/// } +/// ``` +pub fn window_event_listener( event: E, cb: impl Fn(E::EventType) + 'static, ) where diff --git a/leptos_dom/src/html.rs b/leptos_dom/src/html.rs index 8cc70c063..386063cb5 100644 --- a/leptos_dom/src/html.rs +++ b/leptos_dom/src/html.rs @@ -382,26 +382,6 @@ impl HtmlElement { } } - #[doc(hidden)] - #[cfg(not(all(target_arch = "wasm32", feature = "web")))] - #[deprecated = "Use HtmlElement::from_chunks() instead."] - pub fn from_html( - cx: Scope, - element: El, - html: impl Into>, - ) -> Self { - Self { - cx, - attrs: smallvec![], - children: ElementChildren::Chunks(vec![StringOrView::String( - html.into(), - )]), - element, - #[cfg(debug_assertions)] - view_marker: None, - } - } - #[doc(hidden)] #[cfg(not(all(target_arch = "wasm32", feature = "web")))] pub fn from_chunks( diff --git a/leptos_dom/src/node_ref.rs b/leptos_dom/src/node_ref.rs index 5205cf2ee..18a9fa5c8 100644 --- a/leptos_dom/src/node_ref.rs +++ b/leptos_dom/src/node_ref.rs @@ -79,12 +79,6 @@ pub fn create_node_ref( } impl NodeRef { - /// Creates an empty reference. - #[deprecated = "Use `create_node_ref` instead of `NodeRef::new()`."] - pub fn new(cx: Scope) -> Self { - Self(create_rw_signal(cx, None)) - } - /// Gets the element that is currently stored in the reference. /// /// This tracks reactively, so that node references can be used in effects. diff --git a/leptos_reactive/src/signal.rs b/leptos_reactive/src/signal.rs index 0343b9dff..35bc0fb50 100644 --- a/leptos_reactive/src/signal.rs +++ b/leptos_reactive/src/signal.rs @@ -167,18 +167,6 @@ pub trait SignalUpdate { #[track_caller] fn update(&self, f: impl FnOnce(&mut T)); - /// Applies a function to the current value to mutate it in place - /// and notifies subscribers that the signal has changed. Returns - /// [`Some(O)`] if the signal is still valid, [`None`] otherwise. - /// - /// **Note:** `update()` does not auto-memoize, i.e., it will notify subscribers - /// even if the value has not actually changed. - #[deprecated = "Please use `try_update` instead. This method will be \ - removed in a future version of this crate"] - fn update_returning(&self, f: impl FnOnce(&mut T) -> O) -> Option { - self.try_update(f) - } - /// Applies a function to the current value to mutate it in place /// and notifies subscribers that the signal has changed. Returns /// [`Some(O)`] if the signal is still valid, [`None`] otherwise. @@ -249,19 +237,6 @@ pub trait SignalUpdateUntracked { #[track_caller] fn update_untracked(&self, f: impl FnOnce(&mut T)); - /// Runs the provided closure with a mutable reference to the current - /// value without notifying dependents and returns - /// the value the closure returned. - #[deprecated = "Please use `try_update_untracked` instead. This method \ - will be removed in a future version of `leptos`"] - #[inline(always)] - fn update_returning_untracked( - &self, - f: impl FnOnce(&mut T) -> U, - ) -> Option { - self.try_update_untracked(f) - } - /// Runs the provided closure with a mutable reference to the current /// value without notifying dependents and returns /// the value the closure returned. @@ -930,27 +905,6 @@ impl SignalUpdateUntracked for WriteSignal { self.id.update_with_no_effect(self.runtime, f); } - #[cfg_attr( - any(debug_assertions, feature = "ssr"), - instrument( - level = "trace", - name = "WriteSignal::update_returning_untracked()", - skip_all, - fields( - id = ?self.id, - defined_at = %self.defined_at, - ty = %std::any::type_name::() - ) - ) - )] - #[inline(always)] - fn update_returning_untracked( - &self, - f: impl FnOnce(&mut T) -> U, - ) -> Option { - self.id.update_with_no_effect(self.runtime, f) - } - #[inline(always)] fn try_update_untracked( &self, @@ -1345,27 +1299,6 @@ impl SignalUpdateUntracked for RwSignal { self.id.update_with_no_effect(self.runtime, f); } - #[cfg_attr( - any(debug_assertions, features="ssr"), - instrument( - level = "trace", - name = "RwSignal::update_returning_untracked()", - skip_all, - fields( - id = ?self.id, - defined_at = %self.defined_at, - ty = %std::any::type_name::() - ) - ) - )] - #[inline(always)] - fn update_returning_untracked( - &self, - f: impl FnOnce(&mut T) -> U, - ) -> Option { - self.id.update_with_no_effect(self.runtime, f) - } - #[cfg_attr( any(debug_assertions, feature = "ssr"), instrument( diff --git a/leptos_reactive/src/stored_value.rs b/leptos_reactive/src/stored_value.rs index cb1c5683a..e41d73056 100644 --- a/leptos_reactive/src/stored_value.rs +++ b/leptos_reactive/src/stored_value.rs @@ -56,42 +56,8 @@ impl StoredValue { /// } /// let data = store_value(cx, MyCloneableData { value: "a".into() }); /// - /// // calling .get() clones and returns the value - /// assert_eq!(data.get().value, "a"); - /// // there's a short-hand getter form - /// assert_eq!(data().value, "a"); - /// # }); - /// ``` - #[track_caller] - #[deprecated = "Please use `get_value` instead, as this method does not \ - track the stored value. This method will also be removed \ - in a future version of `leptos`"] - pub fn get(&self) -> T - where - T: Clone, - { - self.get_value() - } - - /// Returns a clone of the signals current value, subscribing the effect - /// to this signal. - /// - /// # Panics - /// Panics if you try to access a value stored in a [`Scope`] that has been disposed. - /// - /// # Examples - /// ``` - /// # use leptos_reactive::*; - /// # create_scope(create_runtime(), |cx| { - /// - /// #[derive(Clone)] - /// pub struct MyCloneableData { - /// pub value: String, - /// } - /// let data = store_value(cx, MyCloneableData { value: "a".into() }); - /// - /// // calling .get() clones and returns the value - /// assert_eq!(data.get().value, "a"); + /// // calling .get_value() clones and returns the value + /// assert_eq!(data.get_value().value, "a"); /// // there's a short-hand getter form /// assert_eq!(data().value, "a"); /// # }); @@ -104,18 +70,6 @@ impl StoredValue { self.try_get_value().expect("could not get stored value") } - /// Same as [`StoredValue::get`] but will not panic by default. - #[track_caller] - #[deprecated = "Please use `try_get_value` instead, as this method does \ - not track the stored value. This method will also be \ - removed in a future version of `leptos`"] - pub fn try_get(&self) -> Option - where - T: Clone, - { - self.try_get_value() - } - /// Same as [`StoredValue::get`] but will not panic by default. #[track_caller] pub fn try_get_value(&self) -> Option @@ -125,33 +79,6 @@ impl StoredValue { self.try_with_value(T::clone) } - /// Applies a function to the current stored value. - /// - /// # Panics - /// Panics if you try to access a value stored in a [`Scope`] that has been disposed. - /// - /// # Examples - /// ``` - /// # use leptos_reactive::*; - /// # create_scope(create_runtime(), |cx| { - /// - /// pub struct MyUncloneableData { - /// pub value: String - /// } - /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// - /// // calling .with() to extract the value - /// assert_eq!(data.with(|data| data.value.clone()), "a"); - /// }); - /// ``` - #[track_caller] - #[deprecated = "Please use `with_value` instead, as this method does not \ - track the stored value. This method will also be removed \ - in a future version of `leptos`"] - pub fn with(&self, f: impl FnOnce(&T) -> U) -> U { - self.with_value(f) - } - /// Applies a function to the current stored value. /// /// # Panics @@ -167,8 +94,8 @@ impl StoredValue { /// } /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); /// - /// // calling .with() to extract the value - /// assert_eq!(data.with(|data| data.value.clone()), "a"); + /// // calling .with_value() to extract the value + /// assert_eq!(data.with_value(|data| data.value.clone()), "a"); /// # }); /// ``` #[track_caller] @@ -178,15 +105,6 @@ impl StoredValue { self.try_with_value(f).expect("could not get stored value") } - /// Same as [`StoredValue::with`] but returns [`Some(O)]` only if - /// the signal is still valid. [`None`] otherwise. - #[deprecated = "Please use `try_with_value` instead, as this method does \ - not track the stored value. This method will also be \ - removed in a future version of `leptos`"] - pub fn try_with(&self, f: impl FnOnce(&T) -> O) -> Option { - self.try_with_value(f) - } - /// Same as [`StoredValue::with`] but returns [`Some(O)]` only if /// the signal is still valid. [`None`] otherwise. pub fn try_with_value(&self, f: impl FnOnce(&T) -> O) -> Option { @@ -214,8 +132,8 @@ impl StoredValue { /// pub value: String /// } /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// data.update(|data| data.value = "b".into()); - /// assert_eq!(data.with(|data| data.value.clone()), "b"); + /// data.update_value(|data| data.value = "b".into()); + /// assert_eq!(data.with_value(|data| data.value.clone()), "b"); /// }); /// ``` /// @@ -228,54 +146,12 @@ impl StoredValue { /// } /// /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// let updated = data.update_returning(|data| { + /// let updated = data.try_update_value(|data| { /// data.value = "b".into(); /// data.value.clone() /// }); /// - /// assert_eq!(data.with(|data| data.value.clone()), "b"); - /// assert_eq!(updated, Some(String::from("b"))); - /// # }); - /// ``` - #[track_caller] - #[deprecated = "Please use `update_value` instead, as this method does not \ - track the stored value. This method will also be removed \ - in a future version of `leptos`"] - pub fn update(&self, f: impl FnOnce(&mut T)) { - self.update_value(f); - } - - /// Updates the stored value. - /// - /// # Examples - /// ``` - /// # use leptos_reactive::*; - /// # create_scope(create_runtime(), |cx| { - /// - /// pub struct MyUncloneableData { - /// pub value: String - /// } - /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// data.update(|data| data.value = "b".into()); - /// assert_eq!(data.with(|data| data.value.clone()), "b"); - /// }); - /// ``` - /// - /// ``` - /// use leptos_reactive::*; - /// # create_scope(create_runtime(), |cx| { - /// - /// pub struct MyUncloneableData { - /// pub value: String, - /// } - /// - /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// let updated = data.update_returning(|data| { - /// data.value = "b".into(); - /// data.value.clone() - /// }); - /// - /// assert_eq!(data.with(|data| data.value.clone()), "b"); + /// assert_eq!(data.with_value(|data| data.value.clone()), "b"); /// assert_eq!(updated, Some(String::from("b"))); /// # }); /// ``` @@ -285,18 +161,6 @@ impl StoredValue { .expect("could not set stored value"); } - /// Updates the stored value. - #[track_caller] - #[deprecated = "Please use `try_update_value` instead, as this method does \ - not track the stored value. This method will also be \ - removed in a future version of `leptos`"] - pub fn update_returning( - &self, - f: impl FnOnce(&mut T) -> U, - ) -> Option { - self.try_update_value(f) - } - /// Same as [`Self::update`], but returns [`Some(O)`] if the /// signal is still valid, [`None`] otherwise. pub fn try_update_value(self, f: impl FnOnce(&mut T) -> O) -> Option { @@ -311,29 +175,6 @@ impl StoredValue { .flatten() } - /// Sets the stored value. - /// - /// # Examples - /// ``` - /// # use leptos_reactive::*; - /// # create_scope(create_runtime(), |cx| { - /// - /// pub struct MyUncloneableData { - /// pub value: String - /// } - /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// data.set(MyUncloneableData { value: "b".into() }); - /// assert_eq!(data.with(|data| data.value.clone()), "b"); - /// }); - /// ``` - #[track_caller] - #[deprecated = "Please use `set_value` instead, as this method does not \ - track the stored value. This method will also be removed \ - in a future version of `leptos`"] - pub fn set(&self, value: T) { - self.set_value(value); - } - /// Sets the stored value. /// /// # Examples @@ -345,8 +186,8 @@ impl StoredValue { /// pub value: String, /// } /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); - /// data.set(MyUncloneableData { value: "b".into() }); - /// assert_eq!(data.with(|data| data.value.clone()), "b"); + /// data.set_value(MyUncloneableData { value: "b".into() }); + /// assert_eq!(data.with_value(|data| data.value.clone()), "b"); /// # }); /// ``` #[track_caller] @@ -403,10 +244,10 @@ impl StoredValue { /// pub value: String, /// } /// -/// // ✅ you can move the `StoredValue` and access it with .with() +/// // ✅ you can move the `StoredValue` and access it with .with_value() /// let data = store_value(cx, MyUncloneableData { value: "a".into() }); -/// let callback_a = move || data.with(|data| data.value == "a"); -/// let callback_b = move || data.with(|data| data.value == "b"); +/// let callback_a = move || data.with_value(|data| data.value == "a"); +/// let callback_b = move || data.with_value(|data| data.value == "b"); /// # }).dispose(); /// ``` #[track_caller]