Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Some initial implementation. * Read prepared state during hydration. * Decode each state with bincode. * Feature gate prepared state. * Update documentation. * Switch from base64 to String. * cargo +nightly fmt. * Fix test. * Add some tests. * Minor adjustments. * Remove unused marker. * Update example. * Add use_transitive_state. * Remove unused dead code notation. * Opt for better code size. * Add tests for use_transitive_state. * Fix cargo fmt. * Fix rustdoc. * Asynchronously decode data during hydration. * Fix feature flags. * Fix docs. * Feature flags on ssr_router. * Adjust workflow to reflect feature flags. * Fix features. * Restore wasm-bindgen-futures to be wasm32 only. * Revert wasm-bindgen-futures. * Second attempt to remove wasm-bindgen-futures. * Remove spaces as well. * Address reviews. * Better diagnostic message. * Update diagnostic messages.
- Loading branch information
Showing
36 changed files
with
1,555 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::parse::{Parse, ParseStream}; | ||
use syn::{parse_quote, Expr, ExprClosure, ReturnType, Token, Type}; | ||
|
||
#[derive(Debug)] | ||
pub struct PreparedState { | ||
closure: ExprClosure, | ||
return_type: Type, | ||
deps: Expr, | ||
} | ||
|
||
impl Parse for PreparedState { | ||
fn parse(input: ParseStream) -> syn::Result<Self> { | ||
// Reads a closure. | ||
let expr: Expr = input.parse()?; | ||
|
||
let closure = match expr { | ||
Expr::Closure(m) => m, | ||
other => return Err(syn::Error::new_spanned(other, "expected closure")), | ||
}; | ||
|
||
input.parse::<Token![,]>().map_err(|e| { | ||
syn::Error::new( | ||
e.span(), | ||
"this hook takes 2 arguments but 1 argument was supplied", | ||
) | ||
})?; | ||
|
||
let return_type = match &closure.output { | ||
ReturnType::Default => { | ||
return Err(syn::Error::new_spanned( | ||
&closure, | ||
"You must specify a return type for this closure. This is used when the \ | ||
closure is omitted from the client side rendering bundle.", | ||
)) | ||
} | ||
ReturnType::Type(_rarrow, ty) => *ty.to_owned(), | ||
}; | ||
|
||
// Reads the deps. | ||
let deps = input.parse()?; | ||
|
||
if !input.is_empty() { | ||
let maybe_trailing_comma = input.lookahead1(); | ||
|
||
if !maybe_trailing_comma.peek(Token![,]) { | ||
return Err(maybe_trailing_comma.error()); | ||
} | ||
} | ||
|
||
Ok(Self { | ||
closure, | ||
return_type, | ||
deps, | ||
}) | ||
} | ||
} | ||
|
||
impl PreparedState { | ||
// Async closure is not stable, so we rewrite it to clsoure + async block | ||
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure { | ||
let async_token = match &self.closure.asyncness { | ||
Some(m) => m, | ||
None => return self.closure.clone(), | ||
}; | ||
|
||
let move_token = &self.closure.capture; | ||
let body = &self.closure.body; | ||
|
||
let inner = parse_quote! { | ||
#async_token #move_token { | ||
#body | ||
} | ||
}; | ||
|
||
let mut closure = self.closure.clone(); | ||
|
||
closure.asyncness = None; | ||
// We omit the output type as it's an opaque future type. | ||
closure.output = ReturnType::Default; | ||
|
||
closure.body = inner; | ||
|
||
closure.attrs.push(parse_quote! { #[allow(unused_braces)] }); | ||
|
||
closure | ||
} | ||
|
||
pub fn to_token_stream_with_closure(&self) -> TokenStream { | ||
let deps = &self.deps; | ||
let rt = &self.return_type; | ||
let closure = self.rewrite_to_closure_with_async_block(); | ||
|
||
match &self.closure.asyncness { | ||
Some(_) => quote! { | ||
::yew::functional::use_prepared_state_with_suspension::<#rt, _, _, _>(#closure, #deps) | ||
}, | ||
None => quote! { | ||
::yew::functional::use_prepared_state::<#rt, _, _>(#closure, #deps) | ||
}, | ||
} | ||
} | ||
|
||
// Expose a hook for the client side. | ||
// | ||
// The closure is stripped from the client side. | ||
pub fn to_token_stream_without_closure(&self) -> TokenStream { | ||
let deps = &self.deps; | ||
let rt = &self.return_type; | ||
|
||
quote! { | ||
::yew::functional::use_prepared_state::<#rt, _>(#deps) | ||
} | ||
} | ||
} |
Oops, something went wrong.
b29b453
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yew master branch benchmarks (Lower is better)
yew-struct-keyed 01_run1k
174.806
204.1505
0.86
yew-struct-keyed 02_replace1k
191.269
210.018
0.91
yew-struct-keyed 03_update10th1k_x16
426.5925
421.48
1.01
yew-struct-keyed 04_select1k
60.132
85.28450000000001
0.71
yew-struct-keyed 05_swap1k
86.7955
108.018
0.80
yew-struct-keyed 06_remove-one-1k
29.3165
35.575
0.82
yew-struct-keyed 07_create10k
3261.5505000000003
3420.9745000000003
0.95
yew-struct-keyed 08_create1k-after1k_x2
453.2165
482.12
0.94
yew-struct-keyed 09_clear1k_x8
227.5145
205.782
1.11
yew-struct-keyed 21_ready-memory
1.4553260803222656
1.4598236083984375
1.00
yew-struct-keyed 22_run-memory
1.695892333984375
1.6948318481445312
1.00
yew-struct-keyed 23_update5-memory
1.7000389099121094
1.7120361328125
0.99
yew-struct-keyed 24_run5-memory
1.7169876098632812
1.7175521850585938
1.00
yew-struct-keyed 25_run-clear-memory
1.3335952758789062
1.3321037292480469
1.00
yew-struct-keyed 31_startup-ci
1837.6659999999997
1732.672
1.06
yew-struct-keyed 32_startup-bt
38.636
31.40799999999999
1.23
yew-struct-keyed 33_startup-mainthreadcost
268.2079999999999
261.19199999999995
1.03
yew-struct-keyed 34_startup-totalbytes
331.59765625
331.59765625
1
This comment was automatically generated by workflow using github-action-benchmark.