Skip to content

Commit 3bcb1c5

Browse files
committed
Bumped to 0.1.1
1 parent 1befb2a commit 3bcb1c5

File tree

10 files changed

+50
-45
lines changed

10 files changed

+50
-45
lines changed

CHANGES.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<!-- markdownlint-configure-file { "no-duplicate-heading": { "siblings_only": true } } -->
22
<!-- markdownlint-disable-next-line first-line-h1 -->
3+
## 0.1.1 - 2022-11-10
4+
5+
### Added
6+
7+
* `bind!`, `bind_rc!`, `bind_spawn!` macros
8+
* `driver.get_random()`
9+
* `impl From<Value> for Computed`
10+
11+
### Removed
12+
13+
* BREAKING: Removed `bind`, `bind2`, ... functions
14+
315
## 0.1.0 - 2022-10-20
416

517
### Changed
@@ -53,7 +65,7 @@
5365

5466
### Changed
5567

56-
* Improved initiation of spawn executor
68+
* Improved initiation of spawn executorsrc/list.rs
5769
* Improvements in Graph
5870
* RC-structures, BoxRefCell removed
5971

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vertigo-macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vertigo-macro"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Grzegorz Szeliga <szeligagrzegorz@gmail.com>", "Michał Pokrywka <wolfmoon@o2.pl>"]
55
description = "Reactive Real-DOM library for Rust - macros for html and fetch"
66
edition = "2021"

crates/vertigo-macro/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod bind;
1010

1111
use html_parser::dom_inner;
1212
use proc_macro::TokenStream;
13-
use proc_macro2::{TokenStream as TokenStream2};
13+
use proc_macro2::{TokenStream as TokenStream2, Span};
1414

1515
use crate::{
1616
css_parser::generate_css_string,
@@ -88,7 +88,7 @@ fn convert_to_tokens(input: Result<TokenStream, String>) -> TokenStream {
8888
let empty = "";
8989
quote! { #empty }.into()
9090
}
91-
}
91+
}
9292
}
9393

9494
#[proc_macro]

crates/vertigo/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vertigo"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Grzegorz Szeliga <szeligagrzegorz@gmail.com>", "Michał Pokrywka <wolfmoon@o2.pl>"]
55
description = "Reactive Real-DOM library for Rust"
66
readme = "README.md"
@@ -18,7 +18,7 @@ serde_request = [ "serde_json" ]
1818
[dependencies]
1919
log = { version = "0.4.14", features=["std"] }
2020
serde_json = { version = "1.0", optional = true }
21-
vertigo-macro = { path = "../../crates/vertigo-macro", version="0.1.0" }
21+
vertigo-macro = { path = "../../crates/vertigo-macro", version="0.1.1" }
2222

2323
[dev-dependencies]
2424
serde = { version = "1.0", features = ["derive"] }

demo/app/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vertigo-demo"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Grzegorz Szeliga <szeligagrzegorz@gmail.com>", "Michał Pokrywka <wolfmoon@o2.pl>"]
55
edition = "2021"
66

examples/counter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vertigo-example-counter"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Grzegorz Szeliga <szeligagrzegorz@gmail.com>", "Michał Pokrywka <wolfmoon@o2.pl>"]
55
edition = "2021"
66

examples/router/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vertigo-example-router"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Grzegorz Szeliga <szeligagrzegorz@gmail.com>", "Michał Pokrywka <wolfmoon@o2.pl>"]
55
edition = "2021"
66

examples/trafficlights/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vertigo-example-trafficlights"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["Grzegorz Szeliga <szeligagrzegorz@gmail.com>", "Michał Pokrywka <wolfmoon@o2.pl>"]
55
edition = "2021"
66

tutorial.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Vertigo Tutorial
22

33
<!-- markdownlint-disable-next-line no-emphasis-as-heading -->
4-
*Up to date with version 0.1.0-beta.5*
4+
*Up to date with version 0.1.1*
55

66
<!-- markdownlint-disable-next-line heading-increment -->
77
### Table of contents
@@ -11,11 +11,11 @@
1111
1. [Prepare your system](#1-Prepare-your-system)
1212
2. [Generate project](#2-Generate-project)
1313
3. [First run](#3-First-run)
14-
4. [Render](#4-Initial-code-description)
14+
4. [Initial code description](#4-Initial-code-description)
1515
5. [Add new value](#5-Add-new-value)
1616
6. [Set value](#6-Set-value)
1717
7. [New component](#7-New-component)
18-
8. [Add state to component](#8-Add-state-to-a-component)
18+
8. [Add state to component](#8-Add-state-to-component)
1919
9. [Input element](#9-Input-element)
2020
10. [Computed value](#10-Computed-value)
2121
11. [Parametrized styles](#11-Parametrized-styles)
@@ -218,13 +218,11 @@ In the browser the message should be now in bold.
218218

219219
## 6. Set value
220220

221-
Let's do some reactivity already. Import `vertigo::bind`, add switch closure and use it in `dom!` macro:
221+
Let's do some reactivity already. Import `vertigo::bind`, add switch event and use it in `dom!` macro:
222222

223223
```rust
224-
let switch = bind(&strong).call(|ctx, strong|
225-
strong.set(
226-
!strong.get(ctx)
227-
)
224+
let switch = bind!(strong, ||
225+
strong.change(|val| { *val = !*val; })
228226
);
229227

230228
dom! {
@@ -236,13 +234,10 @@ Let's do some reactivity already. Import `vertigo::bind`, add switch closure and
236234
}
237235
```
238236

239-
To create an event handler in a handy way, vertigo introduces a "binding" mechanism.
237+
To create an event handler in a handy way, vertigo introduces a "bind!" macro.
240238
This reminds a `.bind()` function from JavaScript world, but the reason is different.
241-
Binding a value automatically creates a clone of the value that can be used upon firing the event
242-
(that is, upon invoking `call()` method).
239+
Binding a value automatically creates a clone of the value that can be used upon firing the event.
243240
Happily enough, everything wrapped in a `Value<T>` have a shallow cloning implemented[^clone].
244-
The `call()` method also provides `Context` which allows you to read the values in a responsive way
245-
(using `get(ctx)`[^subscription] method on a `Value`).
246241

247242
## 7. New component
248243

@@ -277,11 +272,6 @@ use list::List;
277272

278273
And use it in main `app()` function:
279274

280-
```rust
281-
```
282-
283-
(...)
284-
285275
```rust
286276
dom! {
287277
<div css={main_div()}>
@@ -293,7 +283,7 @@ And use it in main `app()` function:
293283
}
294284
```
295285

296-
## 8. Add state to a component
286+
## 8. Add state to component
297287

298288
For now our component just shows a static list which is not the usual way of rendering lists.
299289
To go dynamic, add state `elements` to the `mount` function and use it during rendering:
@@ -411,7 +401,7 @@ Our component cries out for adding more items. To implement this we need to:
411401
So the whole `src/list.rs` will look like this:
412402

413403
```rust
414-
use vertigo::{DomElement, dom, Value, bind, bind2};
404+
use vertigo::{DomElement, dom, Value, bind, transaction};
415405

416406
pub struct List {
417407
pub items: Value<Vec<String>>,
@@ -421,14 +411,14 @@ impl List {
421411
pub fn mount(self) -> DomElement {
422412
let new_item = Value::<String>::default();
423413

424-
let add = bind2(&self.items, &new_item).call(|ctx, items, new_item| {
425-
let mut items_vec = items.get(ctx).to_vec();
426-
items_vec.push(new_item.get(ctx));
427-
items.set(items_vec);
428-
new_item.set("".to_string());
414+
let add = bind!(items, new_item, || {
415+
transaction(|ctx| {
416+
items.change(|items| items.push(new_item.get(ctx)));
417+
new_item.set("".to_string());
418+
});
429419
});
430420

431-
let change = bind(&new_item).call_param(|_ctx, new_item, new_value| {
421+
let change = bind!(new_item, |new_value| {
432422
new_item.set(new_value);
433423
});
434424

@@ -453,10 +443,13 @@ impl List {
453443

454444
We've added 2 event handlers in our mount function.
455445

456-
To create **add** handler `bind2` helper is used.
457-
This is similar as `bind` but allows to use 2 parameters during the call. There are also helpers for 3 and 4 parameters.
446+
To create **add** handler, a `transaction` function is used. It allows to do more modifications in one run, and also allows to use more values at the same time.
447+
448+
> Keep in mind though, that values are kept the same during transaction, and only changed during next graph recalculation.
449+
>
450+
> Transaction provides `Context` which allows you to unwrap `Value` for the time of transaction and use it as a regular variable (`get(ctx)`[^subscription] method on a `Value`).
458451
459-
For input **change** event, the `call_param` method is used to create a handler that takes value from the DOM during the call (`new_value` parameter). The type of the value is specialized after applying it in `dom!` macro.
452+
For input **change** event, we are getting `new_value` in the closure. This is a value passed from DOM when executing event handler. The type of the value is specialized after applying it in `dom!` macro.
460453

461454
## 10. Computed value
462455

0 commit comments

Comments
 (0)