Skip to content

Commit

Permalink
v0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Sep 24, 2022
1 parent 2a7d015 commit 9d82cdd
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 33 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## **0.8.2** _(2022-09-24)_

- #### ⚡️ Features

- [Inline props.](https://github.com/sycamore-rs/sycamore/pull/486)
- [`Html::to_web_sys` method.](https://github.com/sycamore-rs/sycamore/pull/490)

- #### 🛠 Fixes

- [Implement `Default` for `Children`.](https://github.com/sycamore-rs/sycamore/commit/d9c3fc6b9783be36b73097aff0137a90f0358214)
- [Implement `From<View>` for `Children`.](https://github.com/sycamore-rs/sycamore/commit/2210e94a66edaa5bf4305ef7bd06c0ca694fdff0)
- [Fix hydration of nodes created using `GenericNode::element_with_tag`.](https://github.com/sycamore-rs/sycamore/commit/aa4eccb7df767174530958fd3e4d1995b4d9a0df)

## **0.8.1** _(2022-09-03)_

- #### 🛠 Fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/next/advanced/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To add routing to your Sycamore app, install the
[`sycamore-router`](https://crates.io/crates/sycamore-router) crate from crates.io.

```toml
sycamore-router = "0.8.0"
sycamore-router = "0.8"
```

### Compatibility with `sycamore`
Expand Down
2 changes: 1 addition & 1 deletion docs/next/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You now need to add Sycamore to your new project's dependencies. Add the followi
`Cargo.toml` file in your project folder:

```toml
sycamore = "0.8.0"
sycamore = "0.8"
```

> **Note**: Sycamore is currently being developed at a rapid pace. To have access to the latest
Expand Down
2 changes: 1 addition & 1 deletion docs/versioned_docs/v0.8/advanced/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To add routing to your Sycamore app, install the
[`sycamore-router`](https://crates.io/crates/sycamore-router) crate from crates.io.

```toml
sycamore-router = "0.8.0"
sycamore-router = "0.8"
```

### Compatibility with `sycamore`
Expand Down
90 changes: 64 additions & 26 deletions docs/versioned_docs/v0.8/basics/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ view! { cx,
}
```

## Reactive data
## Reactive props

Accepting data from the parent sure is nice but it would be even better if updating the data in the
parent also updates the view in the child component! For components to automatically react to prop
Expand Down Expand Up @@ -86,30 +86,7 @@ state.set(1); // automatically updates value in MyComponent

Note how the `'a` lifetime is used to ensure that the data lives as long as the `Scope`.

## Lifecycle

Component lifecycle is strongly tied to the reactive system, since, under the hood, components are
simply functions that are run inside an untracked scope.

This means that we can use the same helpers in the reactive system to attach callbacks to the
component lifecycle.

### `on_cleanup`

The `on_cleanup` method schedules a callback to be called when the reactive scope is destroyed. This
can also be used to schedule a callback when the component is destroyed.

```rust
#[component]
fn MyComponent(cx: Scope) -> View<G> {
on_cleanup(cx, || {
// Perform cleanup.
});
// ...
}
```

### Component children
## Component children

Components can also be wrappers around other child views by adding the `children` field to our
properties struct.
Expand Down Expand Up @@ -139,7 +116,7 @@ view! {
}
```

### Default props
## Default props

Some property fields might have a default value. Use the `#[builder(default)]` attribute to allow
omitting the property when constructing the component.
Expand All @@ -157,3 +134,64 @@ view! { cx,
MyComponent(name="John Doe")
}
```

## `inline_props`

Creating a struct just for accepting a few props might be a bit boilerplate-y depending on your
tastes. Feeling lazy? Just slap `inline_props` onto your component and the function arguments will
automatically be converted into props! For example, the two code snippets below are essentially
identical except that in one case, the struct is manually specified whereas in the other case, it is
automatically generated.

```rust
// Manual method.
#[derive(Prop)]
struct MyProps<'a> {
value: &'a ReadSignal<i32>,
}
#[component]
fn MyComponent<'a, G: Html>(cx: Scope<'a>, props: MyProps<'a>) -> View<G> {
view! {
div(class="my-component") {
"Value: " (props.value.get())
}
}
}

// inline_props for the win!
#[component(inline_props)]
fn MyComponent<'a, G: Html>(cx: Scope<'a>, value: &'a ReadSignal<i32>) -> View<G> {
view! {
div(class="my-component") {
"Value: " (value.get())
}
}
}
```

One thing to keep in mind is that adding `inline_props` makes your function's argument names part of
the public API. Changing the name of the argument also changes the name of the prop and therefore
the users of your component will also need to update their code.

## Lifecycle

Component lifecycle is strongly tied to the reactive system, since, under the hood, components are
simply functions that are run inside an untracked scope.

This means that we can use the same helpers in the reactive system to attach callbacks to the
component lifecycle.

### `on_cleanup`

The `on_cleanup` method schedules a callback to be called when the reactive scope is destroyed. This
can also be used to schedule a callback when the component is destroyed.

```rust
#[component]
fn MyComponent(cx: Scope) -> View<G> {
on_cleanup(cx, || {
// Perform cleanup.
});
// ...
}
```
2 changes: 1 addition & 1 deletion docs/versioned_docs/v0.8/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You now need to add Sycamore to your new project's dependencies. Add the followi
`Cargo.toml` file in your project folder:

```toml
sycamore = "0.8.0"
sycamore = "0.8"
```

> **Note**: Sycamore is currently being developed at a rapid pace. To have access to the latest
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["wasm", "gui", "reactive"]
license = "MIT"
readme = "../../README.md"
repository = "https://github.com/sycamore-rs/sycamore"
version = "0.8.1"
version = "0.8.2"

[lib]
proc-macro = true
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["wasm", "gui", "reactive", "web"]
license = "MIT"
readme = "../../README.md"
repository = "https://github.com/sycamore-rs/sycamore"
version = "0.8.0"
version = "0.8.2"

[dependencies]
html-escape = "0.2.11"
Expand Down
2 changes: 1 addition & 1 deletion packages/sycamore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["wasm", "gui", "reactive"]
license = "MIT"
readme = "../../README.md"
repository = "https://github.com/sycamore-rs/sycamore"
version = "0.8.1"
version = "0.8.2"

[dependencies]
ahash = "0.7.6"
Expand Down

0 comments on commit 9d82cdd

Please sign in to comment.