1use crate::utils::PageFunction;
22use rumtk_core::cache::{new_cache, LazyRUMCache};
23use rumtk_core::strings::RUMString;
24use rumtk_core::{rumtk_cache_get, rumtk_cache_push};
25
26pub type PageCache = LazyRUMCache<RUMString, PageFunction>;
27pub type PageItem = (RUMString, PageFunction);
28pub type UserPages = Vec<PageItem>;
29
30static mut page_cache: PageCache = new_cache();
31
32pub fn register_page(name: &str, component_fxn: PageFunction) {
33 let key = RUMString::from(name);
34 rumtk_cache_push!(&mut page_cache, &key, &component_fxn);
35}
36
37pub fn get_page(name: &str) -> Option<&PageFunction> {
38 rumtk_cache_get!(&mut page_cache, &RUMString::from(name))
39}
40
41pub fn init_pages(user_components: &UserPages) {
42 for itm in user_components {
44 let (name, value) = itm;
45 register_page(name, *value);
46 }
47}
48
49#[macro_export]
50macro_rules! rumtk_web_register_page {
51 ( $key:expr, $fxn:expr ) => {{
52 use $crate::pages::register_page;
53 register_page($key, $fxn)
54 }};
55}
56
57#[macro_export]
58macro_rules! rumtk_web_get_page {
59 ( $key:expr ) => {{
60 use $crate::pages::get_page;
61 get_page($key)
62 }};
63}
64
65#[macro_export]
66macro_rules! rumtk_web_init_pages {
67 ( $pages:expr ) => {{
68 use $crate::pages::init_pages;
69 init_pages($pages)
70 }};
71}