-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reworked builder API * Reorganize module structure * BREAKING CHANGE: Remove unused feature flag * Make child and dynamic child directly accept a ElementBuilder * Add a dyn_if helper method * Add doc tests for new builder API * Remove old builder API * Test all features in CI * Fix doctests * Fix clippy lint * Use new format strings syntax * Do not test all features in miri * Fix clippy lints
- Loading branch information
Showing
16 changed files
with
800 additions
and
887 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
[package] | ||
authors = ["Luke Chu <37006668+lukechu10@users.noreply.github.com>"] | ||
edition = "2021" | ||
name = "hello-builder" | ||
publish = false | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
console_error_panic_hook = "0.1.7" | ||
console_log = "0.2.0" | ||
log = "0.4.14" | ||
sycamore = { path = "../../packages/sycamore", features = ["experimental-builder-html"] } | ||
wasm-bindgen = "0.2.78" | ||
sycamore = { path = "../../packages/sycamore", features = [ | ||
"experimental-builder-agnostic", | ||
] } |
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 |
---|---|---|
@@ -1,31 +1,30 @@ | ||
use sycamore::builder::html::*; | ||
//! Look ma, No `view!`! | ||
//! | ||
//! This example demonstrates the basics of the builder API for constructing views, as an | ||
//! alternative to using the `view!` macro. | ||
use sycamore::builder::prelude::*; | ||
use sycamore::prelude::*; | ||
|
||
#[component] | ||
fn App<G: Html>(ctx: ScopeRef) -> View<G> { | ||
let name = ctx.create_signal(String::new()); | ||
|
||
div(ctx) | ||
.child( | ||
h1(ctx) | ||
.text("Hello ") | ||
.dyn_child(move || { | ||
if *ctx.create_selector(move || !name.get().is_empty()).get() { | ||
span(ctx).dyn_text(move || name.get().to_string()).build() | ||
} else { | ||
span(ctx).text("World").build() | ||
} | ||
}) | ||
.text("!") | ||
.build(), | ||
) | ||
.child(input(ctx).bind_value(name).build()) | ||
.build() | ||
h(div) | ||
.c(h(h1) | ||
.t("Hello ") | ||
.dyn_if( | ||
|| !name.get().is_empty(), | ||
|| h(span).dyn_t(|| name.get().to_string()), | ||
|| h(span).t("World").view(ctx), | ||
) | ||
.t("!")) | ||
.c(h(input).bind_value(name)) | ||
.view(ctx) | ||
} | ||
|
||
fn main() { | ||
console_error_panic_hook::set_once(); | ||
console_log::init_with_level(log::Level::Debug).unwrap(); | ||
|
||
sycamore::render(|ctx| view! {ctx, App() }); | ||
sycamore::render(|ctx| component(|| App(ctx, ()))); | ||
} |
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
Oops, something went wrong.