Skip to content

Commit

Permalink
refactor: renamed template2 to template_rx
Browse files Browse the repository at this point in the history
I've decided that we'll keep both around for the forseeable future, and
`template_rx` is much nicer than `template_with_rx_state`, despite being
slightly less accurate.
  • Loading branch information
arctic-hen7 committed Jan 22, 2022
1 parent f5a7fbd commit 2d99a9a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/rx_state/src/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use perseus::{get_render_ctx, Html, Template};
use sycamore::prelude::{view, Signal};
use sycamore::view::View;

#[perseus::template2(AboutPage)]
#[perseus::template_rx(AboutPage)]
pub fn about_page() -> View<G> {
// Get the page state store manually
// The index page is just an empty string
Expand Down
2 changes: 1 addition & 1 deletion examples/rx_state/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct IndexProps {
// This special macro (normally we'd use `template(IndexProps)`) converts the state we generate elsewhere to a reactive version
// We need to tell it the name of the unreactive properties we created to start with (unfortunately the compiler isn't smart enough to figure that out yet)
// This will also add our reactive properties to the global state store, and, if they're already there, it'll use the existing one
#[perseus::template2(IndexPage)]
#[perseus::template_rx(IndexPage)]
pub fn index_page(IndexPropsRx { username }: IndexPropsRx, global_state: AppStateRx) -> View<G> {
let username_2 = username.clone(); // This is necessary until Sycamore's new reactive primitives are released
let frozen_app = Signal::new(String::new()); // This is not part of our data model, so it's not part of the state properties (everything else should be though)
Expand Down
10 changes: 5 additions & 5 deletions packages/perseus-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod autoserde;
mod head;
mod rx_state;
mod template;
mod template2;
mod template_rx;
mod test;

use darling::FromMeta;
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn template(args: TokenStream, input: TokenStream) -> TokenStream {
}

/// The new version of `#[template]` designed for reactive state. This can interface automatically with global state, and will automatically provide Sycamore `#[component]` annotations. To
/// use this, you'll need to provide your component's name (e.g. `IndexPage`) as `#[template2(IndexPage)]` (just like with the old macro). You can also provide a custom type parameter
/// use this, you'll need to provide your component's name (e.g. `IndexPage`) as `#[template_rx(IndexPage)]` (just like with the old macro). You can also provide a custom type parameter
/// name to use for your component (defaults to `G`) as the second argument.
///
/// The first argument your template function can take is state generated for it (e.g. by the *build state* strategy), but the reactive version (created with `#[make_rx]` usually). From this,
Expand All @@ -85,10 +85,10 @@ pub fn template(args: TokenStream, input: TokenStream) -> TokenStream {
/// **Warning:** this macro is currently exempt from semantic versioning, and breaking changes may be introduced here at any time! If you want stability, use the `#[template]` macro (but you won't
/// get access to Perseus' reactive state platform).
#[proc_macro_attribute]
pub fn template2(args: TokenStream, input: TokenStream) -> TokenStream {
let parsed = syn::parse_macro_input!(input as template2::TemplateFn);
pub fn template_rx(args: TokenStream, input: TokenStream) -> TokenStream {
let parsed = syn::parse_macro_input!(input as template_rx::TemplateFn);
let attr_args = syn::parse_macro_input!(args as syn::AttributeArgs);
template2::template_impl(parsed, attr_args).into()
template_rx::template_impl(parsed, attr_args).into()
}

/// Labels a function as a Perseus head function, which is very similar to a template, but
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/perseus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub use http::Request as HttpRequest;
pub use wasm_bindgen_futures::spawn_local;
/// All HTTP requests use empty bodies for simplicity of passing them around. They'll never need payloads (value in path requested).
pub type Request = HttpRequest<()>;
pub use perseus_macro::{autoserde, head, make_rx, template, template2, test};
pub use perseus_macro::{autoserde, head, make_rx, template, template_rx, test};
pub use sycamore::{generic_node::Html, DomNode, HydrateNode, SsrNode};
pub use sycamore_router::{navigate, Route};

Expand Down

0 comments on commit 2d99a9a

Please sign in to comment.