From c2a3df7a3b307798744d808e864a861da88bd011 Mon Sep 17 00:00:00 2001 From: iRaiko Date: Fri, 20 Jan 2023 10:50:44 +0100 Subject: [PATCH 1/4] chore: added ::new for intermediate type --- packages/perseus-macro/src/rx_state.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/perseus-macro/src/rx_state.rs b/packages/perseus-macro/src/rx_state.rs index 3a7d3ec312..19dda577e1 100644 --- a/packages/perseus-macro/src/rx_state.rs +++ b/packages/perseus-macro/src/rx_state.rs @@ -67,8 +67,10 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { // reactive `struct`s let mut intermediate_fields = quote!(); let mut intermediate_field_makers = quote!(); + let mut new_intermediate_field_makers = quote!(); let mut unrx_field_makers = quote!(); let mut suspense_commands = quote!(); + let mut old_types = quote!(); for field in fields.iter() { let old_ty = field.ty.to_token_stream(); let field_ident = field.ident.as_ref().unwrap(); // It's a `struct`, so this is defined @@ -77,7 +79,11 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { for attr in field.attrs.iter() { field_attrs.extend(attr.to_token_stream()); } - + // Old for ::new implementation of intermediate type + old_types.extend(quote! + { + #field_ident: #old_ty, + }); // Nested fields are left as-is, non-nested ones are wrapped in `RcSignal`s if field.nested { // Nested types should implement the necessary linking traits @@ -86,6 +92,7 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { #field_vis #field_ident: <#old_ty as ::perseus::state::MakeRx>::Rx, }); intermediate_field_makers.extend(quote! { #field_ident: self.#field_ident.make_rx(), }); + new_intermediate_field_makers.extend(quote! { #field_ident: #field_ident.make_rx(), }); unrx_field_makers .extend(quote! { #field_ident: self.#field_ident.clone().make_unrx(), }); @@ -118,6 +125,9 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { intermediate_field_makers.extend( quote! { #field_ident: ::sycamore::prelude::create_rc_signal(self.#field_ident), }, ); + new_intermediate_field_makers.extend( + quote! { #field_ident: ::sycamore::prelude::create_rc_signal(#field_ident), }, + ); // All fields must be `Clone` unrx_field_makers .extend(quote! { #field_ident: (*self.#field_ident.get_untracked()).clone(), }); @@ -177,6 +187,18 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { #intermediate_fields } + impl #intermediate_ident + { + fn new(#old_types) -> #intermediate_ident + { + use ::perseus::state::MakeRx; + #intermediate_ident + { + #new_intermediate_field_makers + } + } + } + impl ::perseus::state::MakeRx for #ident { type Rx = #intermediate_ident; fn make_rx(self) -> Self::Rx { From d1affb2e79fcb3a377c34a05dba15190213d61c2 Mon Sep 17 00:00:00 2001 From: iRaiko Date: Fri, 20 Jan 2023 10:52:23 +0100 Subject: [PATCH 2/4] chore: Add From for intermediate --- packages/perseus-macro/src/rx_state.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/perseus-macro/src/rx_state.rs b/packages/perseus-macro/src/rx_state.rs index 19dda577e1..3ad867a15a 100644 --- a/packages/perseus-macro/src/rx_state.rs +++ b/packages/perseus-macro/src/rx_state.rs @@ -199,6 +199,24 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { } } + impl From<#intermediate_ident> for #ident + { + fn from(value: #intermediate_ident) -> #ident + { + use ::perseus::state::MakeUnrx; + value.make_unrx() + } + } + + impl From<#ident> for #intermediate_ident + { + fn from(value: #ident) -> #intermediate_ident + { + use ::perseus::state::MakeRx; + value.make_rx() + } + } + impl ::perseus::state::MakeRx for #ident { type Rx = #intermediate_ident; fn make_rx(self) -> Self::Rx { From 2c5ddef72062d67f8ccc3048378298f8f65b017e Mon Sep 17 00:00:00 2001 From: iRaiko Date: Thu, 26 Jan 2023 17:09:11 +0100 Subject: [PATCH 3/4] Ran cargo fmt --- packages/perseus-macro/src/rx_state.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/perseus-macro/src/rx_state.rs b/packages/perseus-macro/src/rx_state.rs index 3ad867a15a..6579913386 100644 --- a/packages/perseus-macro/src/rx_state.rs +++ b/packages/perseus-macro/src/rx_state.rs @@ -80,8 +80,7 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { field_attrs.extend(attr.to_token_stream()); } // Old for ::new implementation of intermediate type - old_types.extend(quote! - { + old_types.extend(quote! { #field_ident: #old_ty, }); // Nested fields are left as-is, non-nested ones are wrapped in `RcSignal`s @@ -195,7 +194,7 @@ pub fn make_rx_impl(input: ReactiveStateDeriveInput) -> TokenStream { #intermediate_ident { #new_intermediate_field_makers - } + } } } From 39a07f7fdf4b290113e60b7cde7958151e2decb0 Mon Sep 17 00:00:00 2001 From: iRaiko Date: Tue, 7 Feb 2023 14:54:39 +0100 Subject: [PATCH 4/4] Fix: perseus deploy not adding /mutable --- packages/perseus-cli/src/deploy.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/perseus-cli/src/deploy.rs b/packages/perseus-cli/src/deploy.rs index 397838dda1..20a94ab12b 100644 --- a/packages/perseus-cli/src/deploy.rs +++ b/packages/perseus-cli/src/deploy.rs @@ -151,6 +151,15 @@ fn deploy_full( } .into()); } + let from = dir.join("dist/mutable"); + if let Err(err) = copy_dir(&from, output_path.join("dist"), &CopyOptions::new()) { + return Err(DeployError::MoveDirFailed { + to: output, + from: from.to_str().map(|s| s.to_string()).unwrap(), + source: err, + } + .into()); + } let from = dir.join("dist/render_conf.json"); if let Err(err) = fs::copy(&from, output_path.join("dist/render_conf.json")) { return Err(DeployError::MoveAssetFailed {