Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder API v2 #373

Merged
merged 13 commits into from
Mar 6, 2022
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ jobs:
if: matrix.rust == '1.58.0'
env:
RUN_UI_TESTS: true
run: cargo test
run: cargo test --all-features

- name: Run tests (excluding UI)
run: cargo test
run: cargo test --all-features
if: matrix.rust != '1.58.0'

- name: Run headless browser tests
Expand Down Expand Up @@ -124,6 +124,7 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
# Note that we don't have --all-features for packages/sycamore because of https://github.com/rust-lang/miri/issues/1038
run: |
cd packages/sycamore
cargo miri test
Expand Down
7 changes: 2 additions & 5 deletions docs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn parse(path: &Path) -> Result<MarkdownPage, Box<dyn Error>> {
Some(event)
} else {
let tmp = tmp.take().unwrap();
let anchor = tmp.name.trim().to_lowercase().replace(" ", "-");
let anchor = tmp.name.trim().to_lowercase().replace(' ', "-");
let name = tmp.name.clone();
if level == HeadingLevel::H2 {
outline_tmp.push(tmp);
Expand All @@ -72,10 +72,7 @@ fn parse(path: &Path) -> Result<MarkdownPage, Box<dyn Error>> {
l.children.push(tmp);
}
Some(Event::Html(CowStr::from(format!(
"<{level} id=\"{anchor}\">{name}</{level}>",
level = level,
anchor = anchor,
name = name
"<{level} id=\"{anchor}\">{name}</{level}>"
))))
}
}
Expand Down
9 changes: 4 additions & 5 deletions examples/hello-builder/Cargo.toml
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",
] }
37 changes: 18 additions & 19 deletions examples/hello-builder/src/main.rs
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, ())));
}
2 changes: 1 addition & 1 deletion packages/sycamore-macro/src/view/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Codegen {
let quote_tag = match tag {
ElementTag::Builtin(id) => quote! {
let __el = ::sycamore::generic_node::GenericNode::element(
<::sycamore::html::#id as ::sycamore::html::SycamoreElement>::TAG_NAME
<::sycamore::html::#id as ::sycamore::generic_node::SycamoreElement>::TAG_NAME
);
},
ElementTag::Custom(tag_s) => quote! {
Expand Down
1 change: 0 additions & 1 deletion packages/sycamore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ wasm-bindgen-test = "0.3.29"
default = ["dom", "wasm-bindgen-interning"]
dom = []
experimental-builder-agnostic = []
experimental-builder-html = ["experimental-builder-agnostic"]
experimental-hydrate = ["sycamore-macro/experimental-hydrate"]
ssr = ["html-escape", "once_cell", "experimental-hydrate", "sycamore-macro/ssr"]
suspense = ["futures", "wasm-bindgen-futures", "sycamore-futures"]
Expand Down
Loading