mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
remove old code
This commit is contained in:
parent
def4be80b2
commit
b0cdeab906
1 changed files with 0 additions and 248 deletions
|
@ -120,251 +120,3 @@ mod multi_action;
|
||||||
pub use action::*;
|
pub use action::*;
|
||||||
pub use multi_action::*;
|
pub use multi_action::*;
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//use std::{
|
|
||||||
// collections::HashMap,
|
|
||||||
// sync::{Arc, RwLock},
|
|
||||||
//};
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
///// A concrete type for a server function.
|
|
||||||
//#[derive(Clone)]
|
|
||||||
//pub struct ServerFnTraitObj(pub server_fn::ServerFnTraitObj<()>);
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//impl std::ops::Deref for ServerFnTraitObj {
|
|
||||||
// type Target = server_fn::ServerFnTraitObj<()>;
|
|
||||||
//
|
|
||||||
// fn deref(&self) -> &Self::Target {
|
|
||||||
// &self.0
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//impl std::ops::DerefMut for ServerFnTraitObj {
|
|
||||||
// fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
// &mut self.0
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//impl ServerFnTraitObj {
|
|
||||||
// /// Create a new `ServerFnTraitObj` from a `server_fn::ServerFnTraitObj`.
|
|
||||||
// pub const fn from_generic_server_fn(
|
|
||||||
// server_fn: server_fn::ServerFnTraitObj<()>,
|
|
||||||
// ) -> Self {
|
|
||||||
// Self(server_fn)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//#[cfg(feature = "ssr")]
|
|
||||||
//inventory::collect!(ServerFnTraitObj);
|
|
||||||
//
|
|
||||||
//#[allow(unused)]
|
|
||||||
//type ServerFunction = server_fn::ServerFnTraitObj<()>;
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//lazy_static::lazy_static! {
|
|
||||||
// static ref REGISTERED_SERVER_FUNCTIONS: Arc<RwLock<HashMap<&'static str, ServerFnTraitObj>>> = {
|
|
||||||
// let mut map = HashMap::new();
|
|
||||||
// for server_fn in inventory::iter::<ServerFnTraitObj> {
|
|
||||||
// map.insert(server_fn.0.url(), server_fn.clone());
|
|
||||||
// }
|
|
||||||
// Arc::new(RwLock::new(map))
|
|
||||||
// };
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
///// The registry of all Leptos server functions.
|
|
||||||
//pub struct LeptosServerFnRegistry;
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//impl server_fn::ServerFunctionRegistry<()> for LeptosServerFnRegistry {
|
|
||||||
// type Error = ServerRegistrationFnError;
|
|
||||||
//
|
|
||||||
// /// Server functions are automatically registered on most platforms, (including Linux, macOS,
|
|
||||||
// /// iOS, FreeBSD, Android, and Windows). If you are on another platform, like a WASM server runtime,
|
|
||||||
// /// you should register server functions by calling this `T::register_explicit()`.
|
|
||||||
// fn register_explicit(
|
|
||||||
// prefix: &'static str,
|
|
||||||
// url: &'static str,
|
|
||||||
// server_function: server_fn::SerializedFnTraitObj<()>,
|
|
||||||
// encoding: Encoding,
|
|
||||||
// ) -> Result<(), Self::Error> {
|
|
||||||
// // store it in the hashmap
|
|
||||||
// let mut func_write = REGISTERED_SERVER_FUNCTIONS
|
|
||||||
// .write()
|
|
||||||
// .map_err(|e| ServerRegistrationFnError::Poisoned(e.to_string()))?;
|
|
||||||
// let prev = func_write.insert(
|
|
||||||
// url,
|
|
||||||
// ServerFnTraitObj(server_fn::ServerFnTraitObj::new(
|
|
||||||
// prefix,
|
|
||||||
// url,
|
|
||||||
// encoding,
|
|
||||||
// server_function,
|
|
||||||
// )),
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// // if there was already a server function with this key,
|
|
||||||
// // return Err
|
|
||||||
// match prev {
|
|
||||||
// Some(_) => {
|
|
||||||
// Err(ServerRegistrationFnError::AlreadyRegistered(format!(
|
|
||||||
// "There was already a server function registered at {:?}. \
|
|
||||||
// This can happen if you use the same server function name \
|
|
||||||
// in two different modules
|
|
||||||
// on `stable` or in `release` mode.",
|
|
||||||
// url
|
|
||||||
// )))
|
|
||||||
// }
|
|
||||||
// None => Ok(()),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /// Returns the server function registered at the given URL, or `None` if no function is registered at that URL.
|
|
||||||
// fn get(url: &str) -> Option<server_fn::ServerFnTraitObj<()>> {
|
|
||||||
// REGISTERED_SERVER_FUNCTIONS
|
|
||||||
// .read()
|
|
||||||
// .ok()
|
|
||||||
// .and_then(|fns| fns.get(url).map(|sf| sf.0.clone()))
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /// Returns the server function trait obj registered at the given URL, or `None` if no function is registered at that URL.
|
|
||||||
// fn get_trait_obj(url: &str) -> Option<server_fn::ServerFnTraitObj<()>> {
|
|
||||||
// REGISTERED_SERVER_FUNCTIONS
|
|
||||||
// .read()
|
|
||||||
// .ok()
|
|
||||||
// .and_then(|fns| fns.get(url).map(|sf| sf.0.clone()))
|
|
||||||
// }
|
|
||||||
// /// Return the
|
|
||||||
// fn get_encoding(url: &str) -> Option<Encoding> {
|
|
||||||
// REGISTERED_SERVER_FUNCTIONS
|
|
||||||
// .read()
|
|
||||||
// .ok()
|
|
||||||
// .and_then(|fns| fns.get(url).map(|sf| sf.encoding()))
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /// Returns a list of all registered server functions.
|
|
||||||
// fn paths_registered() -> Vec<&'static str> {
|
|
||||||
// REGISTERED_SERVER_FUNCTIONS
|
|
||||||
// .read()
|
|
||||||
// .ok()
|
|
||||||
// .map(|fns| fns.keys().cloned().collect())
|
|
||||||
// .unwrap_or_default()
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
///// Errors that can occur when registering a server function.
|
|
||||||
//#[derive(
|
|
||||||
// thiserror::Error, Debug, Clone, serde::Serialize, serde::Deserialize,
|
|
||||||
//)]
|
|
||||||
//pub enum ServerRegistrationFnError {
|
|
||||||
// /// The server function is already registered.
|
|
||||||
// #[error("The server function {0} is already registered")]
|
|
||||||
// AlreadyRegistered(String),
|
|
||||||
// /// The server function registry is poisoned.
|
|
||||||
// #[error("The server function registry is poisoned: {0}")]
|
|
||||||
// Poisoned(String),
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///// Get a ServerFunction struct containing info about the server fn
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//pub fn server_fn_by_path(path: &str) -> Option<ServerFnTraitObj> {
|
|
||||||
// REGISTERED_SERVER_FUNCTIONS
|
|
||||||
// .read()
|
|
||||||
// .expect("Server function registry is poisoned")
|
|
||||||
// .get(path)
|
|
||||||
// .cloned()
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///// Attempts to find a server function registered at the given path.
|
|
||||||
/////
|
|
||||||
///// This can be used by a server to handle the requests, as in the following example (using `actix-web`)
|
|
||||||
/////
|
|
||||||
///// ```rust, ignore
|
|
||||||
///// #[post("{tail:.*}")]
|
|
||||||
///// async fn handle_server_fns(
|
|
||||||
///// req: HttpRequest,
|
|
||||||
///// params: web::Path<String>,
|
|
||||||
///// body: web::Bytes,
|
|
||||||
///// ) -> impl Responder {
|
|
||||||
///// let path = params.into_inner();
|
|
||||||
///// let accept_header = req
|
|
||||||
///// .headers()
|
|
||||||
///// .get("Accept")
|
|
||||||
///// .and_then(|value| value.to_str().ok());
|
|
||||||
///// if let Some(server_fn) = server_fn_by_path(path.as_str()) {
|
|
||||||
///// let query = req.query_string().as_bytes();
|
|
||||||
///// let data = match &server_fn.encoding {
|
|
||||||
///// Encoding::Url | Encoding::Cbor => &body,
|
|
||||||
///// Encoding::GetJSON | Encoding::GetCBOR => query,
|
|
||||||
///// };
|
|
||||||
///// match (server_fn.trait_obj)(data).await {
|
|
||||||
///// Ok(serialized) => {
|
|
||||||
///// // if this is Accept: application/json then send a serialized JSON response
|
|
||||||
///// if let Some("application/json") = accept_header {
|
|
||||||
///// HttpResponse::Ok().body(serialized)
|
|
||||||
///// }
|
|
||||||
///// // otherwise, it's probably a <form> submit or something: redirect back to the referrer
|
|
||||||
///// else {
|
|
||||||
///// HttpResponse::SeeOther()
|
|
||||||
///// .insert_header(("Location", "/"))
|
|
||||||
///// .content_type("application/json")
|
|
||||||
///// .body(serialized)
|
|
||||||
///// }
|
|
||||||
///// }
|
|
||||||
///// Err(e) => {
|
|
||||||
///// eprintln!("server function error: {e:#?}");
|
|
||||||
///// HttpResponse::InternalServerError().body(e.to_string())
|
|
||||||
///// }
|
|
||||||
///// }
|
|
||||||
///// } else {
|
|
||||||
///// HttpResponse::BadRequest().body(format!("Could not find a server function at that route."))
|
|
||||||
///// }
|
|
||||||
///// }
|
|
||||||
///// ```
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//pub fn server_fn_trait_obj_by_path(path: &str) -> Option<ServerFnTraitObj> {
|
|
||||||
// server_fn::server_fn_trait_obj_by_path::<(), LeptosServerFnRegistry>(path)
|
|
||||||
// .map(ServerFnTraitObj::from_generic_server_fn)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///// Get the Encoding of a server fn if one is registered at that path. Otherwise, return None
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//pub fn server_fn_encoding_by_path(path: &str) -> Option<Encoding> {
|
|
||||||
// server_fn::server_fn_encoding_by_path::<(), LeptosServerFnRegistry>(path)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///// Returns the set of currently-registered server function paths, for debugging purposes.
|
|
||||||
//#[cfg(any(feature = "ssr", doc))]
|
|
||||||
//pub fn server_fns_by_path() -> Vec<&'static str> {
|
|
||||||
// server_fn::server_fns_by_path::<(), LeptosServerFnRegistry>()
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
///// Defines a "server function." A server function can be called from the server or the client,
|
|
||||||
///// but the body of its code will only be run on the server, i.e., if a crate feature `ssr` is enabled.
|
|
||||||
/////
|
|
||||||
///// (This follows the same convention as the Leptos framework's distinction between `ssr` for server-side rendering,
|
|
||||||
///// and `csr` and `hydrate` for client-side rendering and hydration, respectively.)
|
|
||||||
/////
|
|
||||||
///// Server functions are created using the `server` macro.
|
|
||||||
/////
|
|
||||||
///// The function should be registered by calling `ServerFn::register()`. The set of server functions
|
|
||||||
///// can be queried on the server for routing purposes by calling [server_fn_by_path].
|
|
||||||
/////
|
|
||||||
///// Technically, the trait is implemented on a type that describes the server function's arguments.
|
|
||||||
//pub trait ServerFn: server_fn::ServerFn<()> {
|
|
||||||
// #[cfg(any(feature = "ssr", doc))]
|
|
||||||
// /// Explicitly registers the server function on platforms that require it,
|
|
||||||
// /// allowing the server to query it by URL.
|
|
||||||
// ///
|
|
||||||
// /// Explicit server function registration is no longer required on most platforms
|
|
||||||
// /// (including Linux, macOS, iOS, FreeBSD, Android, and Windows)
|
|
||||||
// fn register_explicit() -> Result<(), ServerFnError> {
|
|
||||||
// Self::register_in_explicit::<LeptosServerFnRegistry>()
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//impl<T> ServerFn for T where T: server_fn::ServerFn<()> {}
|
|
||||||
|
|
Loading…
Reference in a new issue