/
lib.rs
53 lines (44 loc) · 1.27 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#![recursion_limit = "512"]
#[macro_use]
extern crate stdweb;
use stdweb::unstable::TryFrom;
use stdweb::web::Node;
use yew::virtual_dom::VNode;
use yew::{Component, ComponentLink, Html, ShouldRender};
const SVG: &str = r#"
<h2>Inline SVG or <i>any</i> HTML:</h2>
<svg height="250" width="500">
<polygon points="220,10 300,210 170,250 123,234" style="fill:lime;stroke:purple;stroke-width:1" />
Sorry, your browser does not support inline SVG.
</svg>
"#;
pub struct Model {
pub value: i64,
}
pub enum Msg {}
impl Component for Model {
type Message = Msg;
type Properties = ();
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
Model { value: 0 }
}
fn update(&mut self, _: Self::Message) -> ShouldRender {
true
}
fn change(&mut self, _: Self::Properties) -> ShouldRender {
false
}
fn view(&self) -> Html {
let js_svg = js! {
var div = document.createElement("div");
div.innerHTML = @{SVG.to_string()};
console.log(div);
return div;
};
eprintln!("js_svg: {:?}", js_svg);
let node = Node::try_from(js_svg).expect("convert js_svg");
let vnode = VNode::VRef(node);
eprintln!("svg: {:?}", vnode);
vnode
}
}