1use super::{assert_rendered, create_element, RenderFn};
2use dodrio::{builder::*, Node, Render, RenderContext, Vdom};
3use dodrio_js_api::JsRender;
4use futures::channel::oneshot;
7use wasm_bindgen::prelude::*;
8use wasm_bindgen::JsCast;
9use wasm_bindgen_test::*;
16 pub fn new() -> (WrapJs, oneshot::Receiver<()>, Closure<dyn FnMut()>) {
17 let (sender, receiver) = oneshot::channel();
19 let on_after_render = Closure::wrap(Box::new({
20 let mut sender = Some(sender);
24 .expect_throw("on_after_render should only be called once")
26 .expect_throw("receiver should not have been dropped");
28 }) as Box<dyn FnMut()>);
30 let component = WrapJs {
31 inner: JsRender::new(JsComponent::new(&on_after_render)),
34 (component, receiver, on_after_render)
38impl<'a> Render<'a> for WrapJs {
39 fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
41 .attr("class", "wrap-js")
42 .children([self.inner.render(cx)])
49 #[wasm_bindgen(extends = Object)]
50 #[derive(Clone, Debug)]
53 #[wasm_bindgen(constructor)]
54 fn new(on_after_render: &Closure<dyn FnMut()>) -> JsComponent;
57fn eval_js_rendering_component() {
59 static EVAL: Once = Once::new();
61 super::init_logging();
64 window.JsComponent = class JsComponent {
65 constructor(onAfterRender) {
67 this.onAfterRender = onAfterRender;
73 attributes: [{ name: "class", value: "js-component" }],
74 listeners: [{ on: "click", callback: this.onClick.bind(this) }],
76 "Here is some plain text",
79 children: ["...and here is some bold text"]
86 async onClick(vdom, event) {
94 .expect_throw("should eval JS component OK");
99async fn can_use_js_rendering_components() {
100 eval_js_rendering_component();
102 let container = create_element("div");
103 let (component, receiver, _closure) = WrapJs::new();
104 let _vdom = Rc::new(Vdom::new(&container, component));
110 .attr("class", "wrap-js")
112 .attr("class", "js-component")
114 text("Here is some plain text"),
116 .children([text("...and here is some bold text")])
126 .query_selector(".js-component")
127 .expect_throw("should querySelector OK")
128 .expect_throw("should find `.js-component` element OK")
129 .dyn_into::<web_sys::HtmlElement>()
130 .expect_throw("should be an `HTMLElement` object")
133 receiver.await.unwrap();
139 .attr("class", "wrap-js")
141 .attr("class", "js-component")
143 text("Here is some plain text"),
145 .children([text("...and here is some bold text")])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list