dumb ass tryfrom

This commit is contained in:
Michael Zhang 2020-02-08 17:52:19 -06:00
parent 028f8805b2
commit 2827ddbec3
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
2 changed files with 9 additions and 7 deletions

View file

@ -147,7 +147,7 @@ impl Visitor {
match node { match node {
TaggedRsx::Elem(_, Elem { tag, attrs, inner }) => { TaggedRsx::Elem(_, Elem { tag, attrs, inner }) => {
self.impl_code.extend(quote! { self.impl_code.extend(quote! {
fn #make_node_id(&self) -> impl stdweb::web::IElement { fn #make_node_id(&self) -> impl stdweb::web::INode {
let el = document().create_element(#tag).unwrap(); let el = document().create_element(#tag).unwrap();
el el
} }
@ -157,7 +157,7 @@ impl Visitor {
TaggedRsx::Code(_, expr) => { TaggedRsx::Code(_, expr) => {
self.impl_code.extend(quote! { self.impl_code.extend(quote! {
#[inline] #[inline]
fn #make_node_id(&self) -> impl stdweb::web::IElement { fn #make_node_id(&self) -> impl stdweb::web::INode {
let el = document().create_element("span").expect("shouldn't fail"); let el = document().create_element("span").expect("shouldn't fail");
el.set_attribute("id", #node_id); el.set_attribute("id", #node_id);
el el
@ -167,10 +167,12 @@ impl Visitor {
TaggedRsx::Text(_, literal) => { TaggedRsx::Text(_, literal) => {
self.impl_code.extend(quote! { self.impl_code.extend(quote! {
#[inline] #[inline]
fn #make_node_id(&self) -> impl stdweb::web::IElement { fn #make_node_id(&self) -> impl stdweb::web::INode {
let el = document().create_element("span").expect("shouldn't fail"); use stdweb::unstable::TryFrom;
el.set_text_content(#literal); let string: Value = #literal.into();
el let reference = Reference::try_from(string).unwrap();
let node = TextNode::try_from(reference).unwrap();
node
} }
}); });
} }

View file

@ -5,7 +5,7 @@ extern crate stdweb;
mod backend; mod backend;
use stdweb::web::{document, Element, IElement, INode, INonElementParentNode}; use stdweb::{web::{document, Element, IElement, INode, TextNode, INonElementParentNode}, Reference, Value};
use crate::backend::{Backend, Web}; use crate::backend::{Backend, Web};