Argument Defaults

Asteracea provides multiple ways to make working with optional arguments easier.

Like in for example TypeScript, you can specify default parameters for constructor and render arguments:

#![allow(unused)]
fn main() {
asteracea::component! {
  Classic()(
    // This will be improved on in the next chapter.
    class: Option<&'bump str> = None,
  )

  <div
    .class? = {class}
  >
}

asteracea::component! {
  Classical()()

  [
    <*Classic> "\n" // Parameter omitted.
    <*Classic .class = {Some("classicist")}>
  ]
}
}
<DIV></DIV>
<DIV class=classicist></DIV>

Default parameter expressions are normal Rust expressions, and are evaluated as needed if the parameter was not specified.