From f3eff1f088da78b2574acac4c9f031db83fcb95e Mon Sep 17 00:00:00 2001 From: Pauan Date: Sun, 18 Mar 2018 08:49:40 -1000 Subject: [PATCH] Exporting some stuff from stdweb --- examples/animation/src/main.rs | 9 ++------- examples/todomvc/src/main.rs | 7 ++++--- src/dom.rs | 9 ++++++++- src/lib.rs | 6 ++++++ src/macros.rs | 6 ++---- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/animation/src/main.rs b/examples/animation/src/main.rs index c7b3519..547187e 100644 --- a/examples/animation/src/main.rs +++ b/examples/animation/src/main.rs @@ -5,13 +5,11 @@ extern crate dominator; #[macro_use] extern crate futures_signals; -use stdweb::traits::*; -use stdweb::web::{document, HtmlElement}; -use stdweb::web::event::{MouseOverEvent, MouseOutEvent}; use futures_signals::signal::Signal; use futures_signals::signal_vec::unsync::MutableVec; use dominator::traits::*; use dominator::Dom; +use dominator::events::{MouseOverEvent, MouseOutEvent}; use dominator::animation::{Percentage, easing}; use dominator::animation::unsync::MutableAnimation; @@ -117,9 +115,6 @@ fn main() { boxes: MutableVec::new_with_values(vec![0]), }; - // TODO this should be in stdweb - let body = document().query_selector("body").unwrap().unwrap(); - let mut color = 10; let f = clone!(state => move || { @@ -154,7 +149,7 @@ fn main() { );*/ for _ in 0..1 { - dominator::append_dom(&body, + dominator::append_dom(&dominator::body(), html!("div", { style("display", "flex"); diff --git a/examples/todomvc/src/main.rs b/examples/todomvc/src/main.rs index 0312515..355ac16 100644 --- a/examples/todomvc/src/main.rs +++ b/examples/todomvc/src/main.rs @@ -11,7 +11,9 @@ extern crate serde_json; use std::rc::Rc; use std::cell::Cell; -use stdweb::web::{window, document, HtmlElement}; + +// TODO replace most of these with dominator +use stdweb::web::{window, document}; use stdweb::web::event::{InputEvent, ClickEvent, HashChangeEvent, KeyDownEvent, ChangeEvent, DoubleClickEvent, BlurEvent}; use stdweb::web::html_element::InputElement; use stdweb::unstable::TryInto; @@ -176,8 +178,7 @@ fn main() { })); - // TODO this should be in stdweb - let body = document().query_selector("body").unwrap().unwrap(); + let body = dominator::body(); dominator::append_dom(&body, html!("section", { diff --git a/src/dom.rs b/src/dom.rs index 238b7d4..f0336f2 100644 --- a/src/dom.rs +++ b/src/dom.rs @@ -1,7 +1,7 @@ use std; use stdweb::{Reference, Value, ReferenceType}; use stdweb::unstable::{TryFrom, TryInto}; -use stdweb::web::{IEventTarget, INode, IElement, IHtmlElement, Node}; +use stdweb::web::{IEventTarget, INode, IElement, IHtmlElement, HtmlElement, Node}; use stdweb::web::event::ConcreteEvent; use callbacks::Callbacks; use traits::*; @@ -49,6 +49,13 @@ pub const HTML_NAMESPACE: &str = "http://www.w3.org/1999/xhtml"; pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg"; +// TODO this should be in stdweb +// TODO this should return HtmlBodyElement +pub fn body() -> HtmlElement { + js! ( return document.body; ).try_into().unwrap() +} + + pub struct DomHandle { parent: Node, dom: Dom, diff --git a/src/lib.rs b/src/lib.rs index 4e21396..6d47b3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,12 @@ pub use dom::*; pub mod traits; pub mod animation; +pub use stdweb::web::HtmlElement; + +pub mod events { + pub use stdweb::web::event::*; +} + #[cfg(test)] mod tests { diff --git a/src/macros.rs b/src/macros.rs index 6749ddb..8f6cfa7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -10,12 +10,10 @@ macro_rules! html { }}; ($kind:expr) => { - // TODO need better hygiene for HtmlElement - html!($kind => HtmlElement) + html!($kind => $crate::HtmlElement) }; ($kind:expr, { $( $name:ident( $( $args:expr ),* ); )* }) => {{ - // TODO need better hygiene for HtmlElement - html!($kind => HtmlElement, { $( $name( $( $args ),* ); )* }) + html!($kind => $crate::HtmlElement, { $( $name( $( $args ),* ); )* }) }}; }