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