|
| 1 | +use super::{RouteInfo, RouteInfoAtomic, RouteVerdict, RouteVerdictAtomic}; |
1 | 2 | use crate::i18n::Locales;
|
2 | 3 | use crate::template::{ArcTemplateMap, Template, TemplateMap};
|
3 | 4 | use crate::Html;
|
4 | 5 | use std::collections::HashMap;
|
5 | 6 | use std::rc::Rc;
|
6 |
| -use sycamore::prelude::ReadSignal; |
7 |
| -use sycamore::prelude::Signal; |
8 | 7 |
|
9 | 8 | /// The backend for `get_template_for_path` to avoid code duplication for the `Arc` and `Rc` versions.
|
10 | 9 | macro_rules! get_template_for_path {
|
@@ -211,132 +210,3 @@ pub fn match_route_atomic<'a, G: Html>(
|
211 | 210 |
|
212 | 211 | verdict
|
213 | 212 | }
|
214 |
| - |
215 |
| -/// Information about a route, which, combined with error pages and a client-side translations manager, allows the initialization of |
216 |
| -/// the app shell and the rendering of a page. |
217 |
| -#[derive(Debug)] |
218 |
| -pub struct RouteInfo<G: Html> { |
219 |
| - /// The actual path of the route. |
220 |
| - pub path: String, |
221 |
| - /// The template that will be used. The app shell will derive props and a translator to pass to the template function. |
222 |
| - pub template: Rc<Template<G>>, |
223 |
| - /// Whether or not the matched page was incrementally-generated at runtime (if it has been yet). If this is `true`, the server will |
224 |
| - /// use a mutable store rather than an immutable one. See the book for more details. |
225 |
| - pub was_incremental_match: bool, |
226 |
| - /// The locale for the template to be rendered in. |
227 |
| - pub locale: String, |
228 |
| -} |
229 |
| - |
230 |
| -/// The possible outcomes of matching a route. This is an alternative implementation of Sycamore's `Route` trait to enable greater |
231 |
| -/// control and tighter integration of routing with templates. This can only be used if `Routes` has been defined in context (done |
232 |
| -/// automatically by the CLI). |
233 |
| -#[derive(Debug)] |
234 |
| -pub enum RouteVerdict<G: Html> { |
235 |
| - /// The given route was found, and route information is attached. |
236 |
| - Found(RouteInfo<G>), |
237 |
| - /// The given route was not found, and a `404 Not Found` page should be shown. |
238 |
| - NotFound, |
239 |
| - /// The given route maps to the locale detector, which will redirect the user to the attached path (in the appropriate locale). |
240 |
| - LocaleDetection(String), |
241 |
| -} |
242 |
| - |
243 |
| -/// Information about a route, which, combined with error pages and a client-side translations manager, allows the initialization of |
244 |
| -/// the app shell and the rendering of a page. |
245 |
| -/// |
246 |
| -/// This version is designed for multithreaded scenarios, and stores a reference to a template rather than an `Rc<Template<G>>`. That means this is not compatible |
247 |
| -/// with Perseus on the client-side, only on the server-side. |
248 |
| -#[derive(Debug)] |
249 |
| -pub struct RouteInfoAtomic<'a, G: Html> { |
250 |
| - /// The actual path of the route. |
251 |
| - pub path: String, |
252 |
| - /// The template that will be used. The app shell will derive props and a translator to pass to the template function. |
253 |
| - pub template: &'a Template<G>, |
254 |
| - /// Whether or not the matched page was incrementally-generated at runtime (if it has been yet). If this is `true`, the server will |
255 |
| - /// use a mutable store rather than an immutable one. See the book for more details. |
256 |
| - pub was_incremental_match: bool, |
257 |
| - /// The locale for the template to be rendered in. |
258 |
| - pub locale: String, |
259 |
| -} |
260 |
| - |
261 |
| -/// The possible outcomes of matching a route. This is an alternative implementation of Sycamore's `Route` trait to enable greater |
262 |
| -/// control and tighter integration of routing with templates. This can only be used if `Routes` has been defined in context (done |
263 |
| -/// automatically by the CLI). |
264 |
| -/// |
265 |
| -/// This version uses `RouteInfoAtomic`, and is designed for multithreaded scenarios (i.e. on the server). |
266 |
| -#[derive(Debug)] |
267 |
| -pub enum RouteVerdictAtomic<'a, G: Html> { |
268 |
| - /// The given route was found, and route information is attached. |
269 |
| - Found(RouteInfoAtomic<'a, G>), |
270 |
| - /// The given route was not found, and a `404 Not Found` page should be shown. |
271 |
| - NotFound, |
272 |
| - /// The given route maps to the locale detector, which will redirect the user to the attached path (in the appropriate locale). |
273 |
| - LocaleDetection(String), |
274 |
| -} |
275 |
| - |
276 |
| -/// Creates an app-specific routing `struct`. Sycamore expects an `enum` to do this, so we create a `struct` that behaves similarly. If |
277 |
| -/// we don't do this, we can't get the information necessary for routing into the `enum` at all (context and global variables don't suit |
278 |
| -/// this particular case). |
279 |
| -#[macro_export] |
280 |
| -macro_rules! create_app_route { |
281 |
| - { |
282 |
| - name => $name:ident, |
283 |
| - render_cfg => $render_cfg:expr, |
284 |
| - templates => $templates:expr, |
285 |
| - locales => $locales:expr |
286 |
| - } => { |
287 |
| - /// The route type for the app, with all routing logic inbuilt through the generation macro. |
288 |
| - struct $name<G: $crate::Html>($crate::internal::router::RouteVerdict<G>); |
289 |
| - impl<G: $crate::Html> ::sycamore_router::Route for $name<G> { |
290 |
| - fn match_route(path: &[&str]) -> Self { |
291 |
| - let verdict = $crate::internal::router::match_route(path, $render_cfg, $templates, $locales); |
292 |
| - Self(verdict) |
293 |
| - } |
294 |
| - } |
295 |
| - }; |
296 |
| -} |
297 |
| - |
298 |
| -/// The state for the router. |
299 |
| -#[derive(Clone, Debug)] |
300 |
| -pub struct RouterState { |
301 |
| - /// The router's current load state. |
302 |
| - load_state: Signal<RouterLoadState>, |
303 |
| -} |
304 |
| -impl Default for RouterState { |
305 |
| - /// Creates a default instance of the router state intended for server-side usage. |
306 |
| - fn default() -> Self { |
307 |
| - Self { |
308 |
| - load_state: Signal::new(RouterLoadState::Server), |
309 |
| - } |
310 |
| - } |
311 |
| -} |
312 |
| -impl RouterState { |
313 |
| - /// Gets the load state of the router. You'll still need to call `.get()` after this (this just returns a `ReadSignal` to derive other state from in a `create_memo` or the like). |
314 |
| - pub fn get_load_state(&self) -> ReadSignal<RouterLoadState> { |
315 |
| - self.load_state.handle() |
316 |
| - } |
317 |
| - /// Sets the load state of the router. |
318 |
| - pub fn set_load_state(&self, new: RouterLoadState) { |
319 |
| - self.load_state.set(new); |
320 |
| - } |
321 |
| -} |
322 |
| - |
323 |
| -/// The current load state of the router. You can use this to be warned of when a new page is about to be loaded (and display a loading bar or the like, perhaps). |
324 |
| -#[derive(Clone, Debug)] |
325 |
| -pub enum RouterLoadState { |
326 |
| - /// The page has been loaded. |
327 |
| - Loaded { |
328 |
| - /// The name of the template being loaded (mostly for convenience). |
329 |
| - template_name: String, |
330 |
| - /// The full path to the new page being loaded (including the locale, if we're using i18n). |
331 |
| - path: String, |
332 |
| - }, |
333 |
| - /// A new page is being loaded, and will soon replace whatever is currently loaded. The name of the new template is attached. |
334 |
| - Loading { |
335 |
| - /// The name of the template being loaded (mostly for convenience). |
336 |
| - template_name: String, |
337 |
| - /// The full path to the new page being loaded (including the locale, if we're using i18n). |
338 |
| - path: String, |
339 |
| - }, |
340 |
| - /// We're on the server, and there is no router. Whatever you render based on this state will appear when the user first loads the page, before it's made interactive. |
341 |
| - Server, |
342 |
| -} |
0 commit comments