🎨 Convierte el ciclo de renderizado en async
`prepare()` de `Component`, `render()` de `Region` y `Template`, y la implementación de `ComponentRender` pasan a ser funciones async. Se actualizan todos los componentes base, helpers, tests y ejemplos.
This commit is contained in:
parent
9acd8cc51a
commit
9354894b3a
48 changed files with 436 additions and 365 deletions
|
|
@ -121,6 +121,7 @@ pub struct Field {
|
|||
inline: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Field {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -145,7 +146,7 @@ impl Component for Field {
|
|||
self.alter_prop(PropsOp::prepend_classes("form-field form-field-checkboxes"));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
// En `setup()` se garantiza que `name` e `id` están definidos antes del renderizado.
|
||||
let name = self.name().get().unwrap();
|
||||
let container_id = self.id().unwrap();
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ pub struct Checkbox {
|
|||
reverse: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Checkbox {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -95,7 +96,7 @@ impl Component for Checkbox {
|
|||
self.alter_prop(PropsOp::prepend_classes(classes));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
// En `setup()` se garantiza que `name` e `id` están definidos antes del renderizado.
|
||||
let name = self.name().get().unwrap();
|
||||
let container_id = self.id().unwrap();
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ pub struct Form {
|
|||
children: Children,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Form {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -70,7 +71,7 @@ impl Component for Form {
|
|||
self.alter_prop(PropsOp::prepend_classes("form"));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let method = match self.method() {
|
||||
form::Method::Post => Some("post"),
|
||||
form::Method::Get => None,
|
||||
|
|
@ -82,7 +83,7 @@ impl Component for Form {
|
|||
method=[method]
|
||||
accept-charset=[self.charset().get()]
|
||||
{
|
||||
(self.children().render(cx))
|
||||
(self.children().render(cx).await)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ pub struct Fieldset {
|
|||
children: Children,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Fieldset {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -45,8 +46,8 @@ impl Component for Fieldset {
|
|||
self.props.get_id()
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let children = self.children().render(cx);
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let children = self.children().render(cx).await;
|
||||
|
||||
if children.is_empty() {
|
||||
return Ok(html! {});
|
||||
|
|
|
|||
|
|
@ -35,12 +35,13 @@ pub struct Hidden {
|
|||
value: AttrValue,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Hidden {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn prepare(&self, _cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, _cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
Ok(html! {
|
||||
input
|
||||
type="hidden"
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ pub struct Field {
|
|||
inputmode: Attr<Mode>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Field {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -181,7 +182,7 @@ impl Component for Field {
|
|||
)));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let container_id = self.id();
|
||||
let input_id = container_id.as_deref().map(|id| util::join!(id, "-input"));
|
||||
let input_class = if *self.plaintext() {
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ pub struct Field {
|
|||
inline: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Field {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -136,7 +137,7 @@ impl Component for Field {
|
|||
self.alter_prop(PropsOp::prepend_classes("form-field form-field-radios"));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
// En `setup()` se garantiza que `name` e `id` están definidos antes del renderizado.
|
||||
let name = self.name().get().unwrap();
|
||||
let container_id = self.id().unwrap();
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ pub struct Range {
|
|||
disabled: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Range {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -74,7 +75,7 @@ impl Component for Range {
|
|||
self.alter_prop(PropsOp::prepend_classes("form-field form-field-range"));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let container_id = self.id();
|
||||
let range_id = container_id.as_deref().map(|id| util::join!(id, "-range"));
|
||||
Ok(html! {
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ pub struct Field {
|
|||
disabled: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Field {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -233,7 +234,7 @@ impl Component for Field {
|
|||
self.alter_prop(PropsOp::prepend_classes("form-field form-field-select"));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let container_id = self.id();
|
||||
let select_id = container_id.as_deref().map(|id| util::join!(id, "-select"));
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ pub struct Textarea {
|
|||
disabled: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Component for Textarea {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
|
|
@ -84,7 +85,7 @@ impl Component for Textarea {
|
|||
self.alter_prop(PropsOp::prepend_classes("form-field form-field-textarea"));
|
||||
}
|
||||
|
||||
fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let container_id = self.id();
|
||||
let textarea_id = container_id
|
||||
.as_deref()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue