Fix build errors for examples
- The type signature for the method 'render' of Render trait seems to have changed, causing examples to fail.
This commit is contained in:
parent
4c13ecca50
commit
d1525a38ff
|
@ -1,7 +1,7 @@
|
||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
|
|
||||||
use dodrio::builder::text;
|
use dodrio::builder::text;
|
||||||
use dodrio::bumpalo::{self, Bump};
|
use dodrio::bumpalo::{self};
|
||||||
use dodrio::Render;
|
use dodrio::Render;
|
||||||
use log::*;
|
use log::*;
|
||||||
use typed_html::dodrio;
|
use typed_html::dodrio;
|
||||||
|
@ -31,13 +31,11 @@ impl Counter {
|
||||||
|
|
||||||
// The `Render` implementation for `Counter`s displays the current count and has
|
// The `Render` implementation for `Counter`s displays the current count and has
|
||||||
// buttons to increment and decrement the count.
|
// buttons to increment and decrement the count.
|
||||||
impl Render for Counter {
|
impl<'a> Render<'a> for Counter {
|
||||||
fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> dodrio::Node<'bump>
|
fn render(&self, cx: &mut dodrio::RenderContext<'a>) -> dodrio::Node<'a> {
|
||||||
where
|
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
// Stringify the count as a bump-allocated string.
|
// Stringify the count as a bump-allocated string.
|
||||||
let count = bumpalo::format!(in bump, "{}", self.count);
|
let count = bumpalo::format!(in cx.bump, "{}", self.count);
|
||||||
|
let bump = cx.bump;
|
||||||
|
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<div id="counter">
|
<div id="counter">
|
||||||
|
|
|
@ -7,12 +7,12 @@ version = "0.1.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cfg-if = "0.1.7"
|
cfg-if = "0.1.7"
|
||||||
dodrio = "0.2.0"
|
dodrio = "0.2.0"
|
||||||
futures = "0.1.25"
|
futures = "0.3"
|
||||||
js-sys = "0.3.15"
|
js-sys = "0.3.15"
|
||||||
serde = { features = ["derive"], version = "1.0.89" }
|
serde = { features = ["derive"], version = "1.0.89" }
|
||||||
serde_json = "1.0.39"
|
serde_json = "1.0.39"
|
||||||
wasm-bindgen = "0.2.38"
|
wasm-bindgen = "0.2.38"
|
||||||
wasm-bindgen-futures = "0.3.15"
|
wasm-bindgen-futures = "0.4"
|
||||||
typed-html = { path = "../../../typed-html", features = ["dodrio_macro"] }
|
typed-html = { path = "../../../typed-html", features = ["dodrio_macro"] }
|
||||||
|
|
||||||
# Optional dependencies for logging.
|
# Optional dependencies for logging.
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::todos::Todos;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use crate::visibility::Visibility;
|
use crate::visibility::Visibility;
|
||||||
use dodrio::VdomWeak;
|
use dodrio::VdomWeak;
|
||||||
use futures::prelude::*;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
@ -30,7 +29,8 @@ pub fn start(vdom: VdomWeak) {
|
||||||
v
|
v
|
||||||
});
|
});
|
||||||
|
|
||||||
wasm_bindgen_futures::spawn_local(
|
let vdom = vdom.clone();
|
||||||
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
vdom.with_component({
|
vdom.with_component({
|
||||||
let vdom = vdom.clone();
|
let vdom = vdom.clone();
|
||||||
move |root| {
|
move |root| {
|
||||||
|
@ -45,8 +45,9 @@ pub fn start(vdom: VdomWeak) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map_err(|_| ()),
|
.await
|
||||||
);
|
.ok();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call it once to handle the initial `#` fragment.
|
// Call it once to handle the initial `#` fragment.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Type definition and `dodrio::Render` implementation for a single todo item.
|
//! Type definition and `dodrio::Render` implementation for a single todo item.
|
||||||
|
|
||||||
use crate::keys;
|
use crate::keys;
|
||||||
use dodrio::{bumpalo::Bump, Node, Render, RootRender, VdomWeak};
|
use dodrio::{bumpalo::Bump, Node, Render, RenderContext, RootRender, VdomWeak};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use typed_html::dodrio;
|
use typed_html::dodrio;
|
||||||
|
@ -93,17 +93,16 @@ impl<C> Todo<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: TodoActions> Render for Todo<C> {
|
impl<'a, C: TodoActions> Render<'a> for Todo<C> {
|
||||||
fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
|
fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
|
||||||
where
|
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
use dodrio::{builder::text, bumpalo};
|
use dodrio::{builder::text, bumpalo};
|
||||||
use typed_html::types::ClassList;
|
use typed_html::types::ClassList;
|
||||||
|
|
||||||
let id = self.id;
|
let id = self.id;
|
||||||
let title = self.edits.as_ref().unwrap_or(&self.title);
|
let title = self.edits.as_ref().unwrap_or(&self.title);
|
||||||
|
let title = bumpalo::collections::String::from_str_in(title, cx.bump).into_bump_str();
|
||||||
|
|
||||||
|
let bump = cx.bump;
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<li class={
|
<li class={
|
||||||
let mut class = ClassList::new();
|
let mut class = ClassList::new();
|
||||||
|
@ -130,7 +129,7 @@ impl<C: TodoActions> Render for Todo<C> {
|
||||||
C::delete(root, vdom, id)
|
C::delete(root, vdom, id)
|
||||||
}}/>
|
}}/>
|
||||||
</div>
|
</div>
|
||||||
<input class="edit" value={title.as_str()} name="title" id={
|
<input class="edit" value={title} name="title" id={
|
||||||
bumpalo::format!(in bump, "todo-{}", id).into_bump_str()
|
bumpalo::format!(in bump, "todo-{}", id).into_bump_str()
|
||||||
} oninput={move |root, vdom, event| {
|
} oninput={move |root, vdom, event| {
|
||||||
let input = event
|
let input = event
|
||||||
|
|
|
@ -5,9 +5,10 @@ use crate::controller::Controller;
|
||||||
use crate::todo::{Todo, TodoActions};
|
use crate::todo::{Todo, TodoActions};
|
||||||
use crate::visibility::Visibility;
|
use crate::visibility::Visibility;
|
||||||
use crate::{keys, utils};
|
use crate::{keys, utils};
|
||||||
|
use dodrio::RenderContext;
|
||||||
use dodrio::{
|
use dodrio::{
|
||||||
builder::text,
|
builder::text,
|
||||||
bumpalo::{self, Bump},
|
bumpalo::{self},
|
||||||
Node, Render, RootRender, VdomWeak,
|
Node, Render, RootRender, VdomWeak,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -138,10 +139,8 @@ impl<C> Todos<C> {
|
||||||
|
|
||||||
/// Rendering helpers.
|
/// Rendering helpers.
|
||||||
impl<C: TodosActions> Todos<C> {
|
impl<C: TodosActions> Todos<C> {
|
||||||
fn header<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
|
fn header<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
|
||||||
where
|
let bump = cx.bump;
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<h1>"todos"</h1>
|
<h1>"todos"</h1>
|
||||||
|
@ -161,13 +160,10 @@ impl<C: TodosActions> Todos<C> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn todos_list<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
|
fn todos_list<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
|
||||||
where
|
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
use dodrio::bumpalo::collections::Vec;
|
use dodrio::bumpalo::collections::Vec;
|
||||||
|
|
||||||
let mut todos = Vec::with_capacity_in(self.todos.len(), bump);
|
let mut todos = Vec::with_capacity_in(self.todos.len(), cx.bump);
|
||||||
todos.extend(
|
todos.extend(
|
||||||
self.todos
|
self.todos
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -176,9 +172,10 @@ impl<C: TodosActions> Todos<C> {
|
||||||
Visibility::Active => !t.is_complete(),
|
Visibility::Active => !t.is_complete(),
|
||||||
Visibility::Completed => t.is_complete(),
|
Visibility::Completed => t.is_complete(),
|
||||||
})
|
})
|
||||||
.map(|t| t.render(bump)),
|
.map(|t| t.render(cx)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let bump = cx.bump;
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<section class="main" style={
|
<section class="main" style={
|
||||||
if self.todos.is_empty() {
|
if self.todos.is_empty() {
|
||||||
|
@ -200,10 +197,7 @@ impl<C: TodosActions> Todos<C> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn footer<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
|
fn footer<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
|
||||||
where
|
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
let completed_count = self.todos.iter().filter(|t| t.is_complete()).count();
|
let completed_count = self.todos.iter().filter(|t| t.is_complete()).count();
|
||||||
let incomplete_count = self.todos.len() - completed_count;
|
let incomplete_count = self.todos.len() - completed_count;
|
||||||
let items_left = if incomplete_count == 1 {
|
let items_left = if incomplete_count == 1 {
|
||||||
|
@ -211,14 +205,15 @@ impl<C: TodosActions> Todos<C> {
|
||||||
} else {
|
} else {
|
||||||
" items left"
|
" items left"
|
||||||
};
|
};
|
||||||
let incomplete_count = bumpalo::format!(in bump, "{}", incomplete_count);
|
let incomplete_count = bumpalo::format!(in cx.bump, "{}", incomplete_count);
|
||||||
|
|
||||||
let clear_completed_text = bumpalo::format!(
|
let clear_completed_text = bumpalo::format!(
|
||||||
in bump,
|
in cx.bump,
|
||||||
"Clear completed ({})",
|
"Clear completed ({})",
|
||||||
self.todos.iter().filter(|t| t.is_complete()).count()
|
self.todos.iter().filter(|t| t.is_complete()).count()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let bump = cx.bump;
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<footer class="footer" hidden={self.todos.is_empty()}>
|
<footer class="footer" hidden={self.todos.is_empty()}>
|
||||||
<span class="todo-count">
|
<span class="todo-count">
|
||||||
|
@ -229,9 +224,9 @@ impl<C: TodosActions> Todos<C> {
|
||||||
</span>
|
</span>
|
||||||
<ul class="filters">
|
<ul class="filters">
|
||||||
{ bumpalo::vec![in ≎
|
{ bumpalo::vec![in ≎
|
||||||
self.visibility_swap(bump, "#/", Visibility::All),
|
self.visibility_swap(cx, "#/", Visibility::All),
|
||||||
self.visibility_swap(bump, "#/active", Visibility::Active),
|
self.visibility_swap(cx, "#/active", Visibility::Active),
|
||||||
self.visibility_swap(bump, "#/completed", Visibility::Completed)
|
self.visibility_swap(cx, "#/completed", Visibility::Completed)
|
||||||
] }
|
] }
|
||||||
</ul>
|
</ul>
|
||||||
<button class="clear-completed" hidden={completed_count == 0} onclick={|root, vdom, _event| {
|
<button class="clear-completed" hidden={completed_count == 0} onclick={|root, vdom, _event| {
|
||||||
|
@ -241,15 +236,13 @@ impl<C: TodosActions> Todos<C> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visibility_swap<'a, 'bump>(
|
fn visibility_swap<'a>(
|
||||||
&'a self,
|
&self,
|
||||||
bump: &'bump Bump,
|
cx: &mut RenderContext<'a>,
|
||||||
url: &'static str,
|
url: &'static str,
|
||||||
target_vis: Visibility,
|
target_vis: Visibility,
|
||||||
) -> Node<'bump>
|
) -> Node<'a> {
|
||||||
where
|
let bump = cx.bump;
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<li onclick={move |root, vdom, _event| {
|
<li onclick={move |root, vdom, _event| {
|
||||||
C::change_visibility(root, vdom, target_vis);
|
C::change_visibility(root, vdom, target_vis);
|
||||||
|
@ -266,14 +259,12 @@ impl<C: TodosActions> Todos<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: TodosActions> Render for Todos<C> {
|
impl<'a, C: TodosActions> Render<'a> for Todos<C> {
|
||||||
fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
|
fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
|
||||||
where
|
let bump = cx.bump;
|
||||||
'a: 'bump,
|
|
||||||
{
|
|
||||||
dodrio!(bump,
|
dodrio!(bump,
|
||||||
<div>{ bumpalo::vec![in ≎
|
<div>{ bumpalo::vec![in ≎
|
||||||
self.header(bump), self.todos_list(bump), self.footer(bump)
|
self.header(cx), self.todos_list(cx), self.footer(cx)
|
||||||
] }</div>
|
] }</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue