Skip to content

Commit 851e980

Browse files
committed
Updated docs for beta4
1 parent dcef925 commit 851e980

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

crates/vertigo/src/bind.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::future::Future;
33
use crate::{get_driver, Context};
44

5+
/// Allows to create an event handler based on 1 parameter
56
pub fn bind<T1: Clone>(param1: &T1) -> Bind1<T1> {
67
let param1 = param1.clone();
78

@@ -10,18 +11,21 @@ pub fn bind<T1: Clone>(param1: &T1) -> Bind1<T1> {
1011
}
1112
}
1213

14+
/// Event handler factory having 1 parameter in context
1315
pub struct Bind1<T1> {
1416
param1: T1,
1517
}
1618

1719
impl<T1: Clone> Bind1<T1> {
20+
/// Extend this creator to a 2-parameter one
1821
pub fn and<T2: Clone>(self, param2: &T2) -> Bind2<T1, T2> {
1922
Bind2 {
2023
param1: self.param1,
2124
param2: param2.clone(),
2225
}
2326
}
2427

28+
/// Create event handler that doesn't accept a parameter
2529
pub fn call<R>(self, fun: fn(&Context, &T1) -> R) -> impl Fn() -> R {
2630
let Self { param1 } = self;
2731

@@ -31,6 +35,7 @@ impl<T1: Clone> Bind1<T1> {
3135
}
3236
}
3337

38+
/// Create event handler that accepts a parameter
3439
pub fn call_param<T2, R>(self, fun: fn(&Context, &T1, T2) -> R) -> impl Fn(T2) -> R {
3540
let Self { param1 } = self;
3641

@@ -40,6 +45,7 @@ impl<T1: Clone> Bind1<T1> {
4045
}
4146
}
4247

48+
/// Run async code
4349
pub fn spawn<
4450
Fut: Future<Output=Context> + 'static
4551
>(self, fun: fn(Context, T1) -> Fut) -> impl Fn() {
@@ -56,19 +62,22 @@ impl<T1: Clone> Bind1<T1> {
5662
}
5763
}
5864

65+
/// Allows to create an event handler based on 2 parameters
5966
pub fn bind2<T1: Clone, T2: Clone>(param1: &T1, param2: &T2) -> Bind2<T1, T2> {
6067
Bind2 {
6168
param1: param1.clone(),
6269
param2: param2.clone()
6370
}
6471
}
6572

73+
/// Event handler factory having 2 parameters in context
6674
pub struct Bind2<T1, T2> {
6775
param1: T1,
6876
param2: T2,
6977
}
7078

7179
impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
80+
/// Extend this creator to a 3-parameter one
7281
pub fn and<T3: Clone>(self, param3: &T3) -> Bind3<T1, T2, T3> {
7382
Bind3 {
7483
param1: self.param1,
@@ -77,6 +86,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
7786
}
7887
}
7988

89+
/// Create event handler that doesn't accept a parameter
8090
pub fn call<R>(self, fun: fn(&Context, &T1, &T2) -> R) -> impl Fn() -> R {
8191
let Self { param1, param2 } = self;
8292

@@ -86,6 +96,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
8696
}
8797
}
8898

99+
/// Create event handler that accepts a parameter
89100
pub fn call_param<T3, R>(self, fun: fn(&Context, &T1, &T2, T3) -> R) -> impl Fn(T3) -> R {
90101
let Self { param1, param2 } = self;
91102

@@ -95,6 +106,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
95106
}
96107
}
97108

109+
/// Run async code
98110
pub fn spawn<
99111
Fut: Future<Output=Context> + 'static
100112
>(self, fun: fn(Context, T1, T2) -> Fut) -> impl Fn() {
@@ -112,6 +124,7 @@ impl<T1: Clone, T2: Clone> Bind2<T1, T2> {
112124
}
113125
}
114126

127+
/// Allows to create an event handler based on 3 parameters
115128
pub fn bind3<T1: Clone, T2: Clone, T3: Clone>(param1: &T1, param2: &T2, param3: &T3) -> Bind3<T1, T2, T3> {
116129
Bind3 {
117130
param1: param1.clone(),
@@ -120,13 +133,15 @@ pub fn bind3<T1: Clone, T2: Clone, T3: Clone>(param1: &T1, param2: &T2, param3:
120133
}
121134
}
122135

136+
/// Event handler factory having 3 parameters in context
123137
pub struct Bind3<T1, T2, T3> {
124138
param1: T1,
125139
param2: T2,
126140
param3: T3,
127141
}
128142

129143
impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
144+
/// Extend this creator to a 4-parameter one
130145
pub fn and<T4: Clone>(self, param4: &T4) -> Bind4<T1, T2, T3, T4> {
131146
Bind4 {
132147
param1: self.param1,
@@ -136,6 +151,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
136151
}
137152
}
138153

154+
/// Create event handler that doesn't accept a parameter
139155
pub fn call<R>(self, fun: fn(&Context, &T1, &T2, &T3) -> R) -> impl Fn() -> R {
140156
let Self { param1, param2, param3 } = self;
141157

@@ -145,6 +161,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
145161
}
146162
}
147163

164+
/// Create event handler that accepts a parameter
148165
pub fn call_param<T4, R>(self, fun: fn(&Context, &T1, &T2, &T3, T4) -> R) -> impl Fn(T4) -> R {
149166
let Self { param1, param2, param3 } = self;
150167

@@ -154,6 +171,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
154171
}
155172
}
156173

174+
/// Run async code
157175
pub fn spawn<
158176
Fut: Future<Output=Context> + 'static
159177
>(self, fun: fn(Context, T1, T2, T3) -> Fut) -> impl Fn() {
@@ -172,6 +190,7 @@ impl<T1: Clone, T2: Clone, T3: Clone> Bind3<T1, T2, T3> {
172190
}
173191
}
174192

193+
/// Allows to create an event handler based on 4 parameters
175194
pub fn bind4<T1: Clone, T2: Clone, T3: Clone, T4: Clone>(param1: &T1, param2: &T2, param3: &T3, param4: &T4) -> Bind4<T1, T2, T3, T4> {
176195
Bind4 {
177196
param1: param1.clone(),
@@ -181,6 +200,7 @@ pub fn bind4<T1: Clone, T2: Clone, T3: Clone, T4: Clone>(param1: &T1, param2: &T
181200
}
182201
}
183202

203+
/// Event handler factory having 4 parameters in context
184204
pub struct Bind4<T1, T2, T3, T4> {
185205
param1: T1,
186206
param2: T2,
@@ -189,6 +209,7 @@ pub struct Bind4<T1, T2, T3, T4> {
189209
}
190210

191211
impl<T1: Clone, T2: Clone, T3: Clone, T4: Clone> Bind4<T1, T2, T3, T4> {
212+
/// Create event handler that doesn't accept a parameter
192213
pub fn call<R>(self, fun: fn(&Context, &T1, &T2, &T3, &T4) -> R) -> impl Fn() -> R {
193214
let Self { param1, param2, param3, param4 } = self;
194215

@@ -198,6 +219,7 @@ impl<T1: Clone, T2: Clone, T3: Clone, T4: Clone> Bind4<T1, T2, T3, T4> {
198219
}
199220
}
200221

222+
/// Create event handler that accepts a parameter
201223
pub fn call_param<T5, R>(self, fun: fn(&Context, &T1, &T2, &T3, &T4, T5) -> R) -> impl Fn(T5) -> R {
202224
let Self { param1, param2, param3, param4 } = self;
203225

@@ -207,6 +229,7 @@ impl<T1: Clone, T2: Clone, T3: Clone, T4: Clone> Bind4<T1, T2, T3, T4> {
207229
}
208230
}
209231

232+
/// Run async code
210233
pub fn spawn<
211234
Fut: Future<Output=Context> + 'static,
212235
>(self, fun: fn(Context, T1, T2, T3, T4) -> Fut) -> impl Fn() {

crates/vertigo/src/dom/dom_comment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{Driver, struct_mut::VecMut, get_driver, Client};
22
use super::dom_id::DomId;
33

4+
/// A Real DOM representative - comment kind
45
pub struct DomComment {
56
driver: Driver,
67
pub id_dom: DomId,

crates/vertigo/src/dom/dom_element.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl PartialEq for DomElementRef {
7575
}
7676
}
7777

78+
/// A Real DOM representative - element kind
7879
pub struct DomElement {
7980
driver: Driver,
8081
id_dom: DomId,

crates/vertigo/src/dom/dom_node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{dom::{
55

66
use super::{dom_id::DomId, dom_comment::DomComment};
77

8+
/// A Real DOM representative
89
pub enum DomNode {
910
Node { node: DomElement },
1011
Text { node: DomText },
@@ -53,7 +54,7 @@ impl<T: Into<String>> From<T> for DomNode {
5354
}
5455
}
5556

56-
57+
/// DomNode not connected yet to any parent
5758
pub enum DomNodeFragment {
5859
Node { node: DomElement },
5960
Text { node: DomText },

crates/vertigo/src/dom/dom_text.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl<T: Clone + 'static> ToComputed<T> for &Value<T> {
3232
}
3333

3434

35+
/// A Real DOM representative - text kind
3536
pub struct DomText {
3637
driver: Driver,
3738
id_dom: DomId,

crates/vertigo/src/dom_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn render_list<
6464
let get_key = get_key.clone();
6565
let render = render.clone();
6666
let parent = parent.clone();
67-
67+
6868
move |current| {
6969
let current_list = std::mem::take(current);
7070

@@ -76,7 +76,7 @@ pub fn render_list<
7676
get_key.clone(),
7777
render,
7878
);
79-
79+
8080

8181
let list_refs = get_refs(&new_order);
8282
*current = new_order;

crates/vertigo/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
//!
33
//! It mainly consists of three parts:
44
//!
5-
//! * **Virtual DOM** - Lightweight representation of JavaScript DOM that can be used to optimally update real DOM
6-
//! * **Reactive dependencies** - A graph of values and clients that can automatically compute what to refresh after one value change
7-
//! * **HTML/CSS macros** - Allows to construct Virtual DOM nodes using HTML and CSS
5+
//! * **Reactive dependencies** - A graph of values and clients (micro-subscriptions) that can automatically compute what to refresh after one value change
6+
//! * **Real DOM** - No intermediate Virtual DOM mechanism is necessary
7+
//! * **HTML/CSS macros** - Allows to construct Real DOM nodes using HTML and CSS
88
//!
99
//! ## Example
1010
//!
1111
//! ```rust
12-
//! use vertigo::{Computed, DomElement, Value, dom, css_fn};
12+
//! use vertigo::{DomElement, Value, dom, css_fn};
1313
//!
1414
//! pub struct State {
1515
//! pub message: Value<String>,
@@ -33,7 +33,7 @@
3333
//! dom! {
3434
//! <div css={main_div()}>
3535
//! "Message to the world: "
36-
//! <text computed={&state.message} />
36+
//! { state.message }
3737
//! </div>
3838
//! }
3939
//! }
@@ -93,7 +93,7 @@ pub use dom::types::{
9393
};
9494
pub use websocket::{WebsocketConnection, WebsocketMessage};
9595
pub use future_box::{FutureBoxSend, FutureBox};
96-
pub use bind::{bind, bind2, bind3, bind4};
96+
pub use bind::{bind, bind2, bind3, bind4, Bind1, Bind2, Bind3, Bind4};
9797
pub use driver_module::driver::{FetchMethod};
9898
pub use dom::{
9999
dom_id::DomId,

0 commit comments

Comments
 (0)