Skip to content

Commit

Permalink
[augdom] use prettiest for debug printing
Browse files Browse the repository at this point in the history
  • Loading branch information
anp committed Aug 24, 2020
1 parent d22e812 commit e62edd7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 228 deletions.
3 changes: 2 additions & 1 deletion dom/augdom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ all-features = true
[features]
default = ["webdom"]
rsdom = []
webdom = ["gloo-timers", "js-sys", "wasm-bindgen", "web-sys"]
webdom = ["gloo-timers", "js-sys", "prettiest", "wasm-bindgen", "web-sys"]

[dependencies]
futures = "0.3.5"
Expand All @@ -30,6 +30,7 @@ static_assertions = "1"

# webdom dependencies:
js-sys = { version = "0.3.25", optional = true }
prettiest = { version = "0.1.0", path = "../prettiest", optional = true }
wasm-bindgen = { version = "0.2.48", optional = true }

[dependencies.web-sys]
Expand Down
11 changes: 4 additions & 7 deletions dom/augdom/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ use crate::Node;
#[cfg(feature = "webdom")]
use {
crate::webdom,
prettiest::Pretty,
std::fmt::{Debug, Formatter, Result as FmtResult},
wasm_bindgen::{prelude::*, JsCast},
web_sys as sys,
};

#[cfg(feature = "webdom")]
mod debug;

/// An event that can be received as the first argument to a handler callback.
#[cfg(feature = "webdom")]
pub trait Event: AsRef<web_sys::Event> + JsCast {
Expand Down Expand Up @@ -147,10 +145,9 @@ macro_rules! event_ty {

impl Debug for $name {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
f.write_fmt(format_args!(
"{:?}",
debug::JsFormatter::new(stringify!($name), &self.0),
))
let val: &JsValue = self.0.as_ref();
let pretty = Pretty::from(val.clone());
pretty.fmt(f)
}
}
};
Expand Down
217 changes: 0 additions & 217 deletions dom/augdom/src/event/debug.rs

This file was deleted.

10 changes: 7 additions & 3 deletions dom/augdom/src/webdom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use super::Node;
use crate::document;
use futures::{channel::mpsc::UnboundedReceiver, Stream};
use prettiest::Pretty;
use std::{
io::Write,
pin::Pin,
Expand All @@ -23,9 +24,12 @@ impl Callback {
where
T: JsCast,
{
let cb = Closure::wrap(Box::new(move |v: JsValue| {
let v: T = v.dyn_into().unwrap();
cb(v);
let cb = Closure::wrap(Box::new(move |raw: JsValue| {
let value = raw
.dyn_into()
.map_err(|v| Pretty::from(v))
.expect("must be able to cast into expected callback input");
cb(value);
}) as Box<dyn FnMut(JsValue)>);
Self { cb }
}
Expand Down
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ <h3>
pure Rust which can be used for testing or to render HTML strings.
</p>

<h3>
prettiest
<a href="target/doc/prettiest/index.html">
<img src="https://img.shields.io/badge/docs-main-steelblue" alt="prettiest main branch docs badge"
align="right" />
</a>
<a href="https://docs.rs/prettiest">
<img src="https://docs.rs/prettiest/badge.svg" alt="prettiest docs badge" align="right" />
</a>
<a href="https://crates.io/crates/prettiest">
<img src="https://img.shields.io/crates/v/prettiest?color=steelblue" alt="prettiest version badge"
align="right" />
</a>
</h3>
<p>
pretty-printer for javascript values from <a target="_blank"
href="https://docs.rs/wasm-bindgen">wasm-bindgen</a>
</p>

<h3>
raf
<a href="target/doc/raf/index.html">
Expand Down

0 comments on commit e62edd7

Please sign in to comment.