chore: add some fixes to hot reload
This commit is contained in:
1 parent
079d71fb2b
commit
366e46eddf
4 files changed
+34
-19
No files matched your search
@@ -121,12 +121,10 @@ impl WebsysDom {
|
||||
} = attr
|
||||
{
|
||||
match namespace {
|
||||
Some(ns) if *ns == "style" => el
|
||||
.dyn_ref::<HtmlElement>()
|
||||
.unwrap()
|
||||
.style()
|
||||
.set_property(name, value)
|
||||
.unwrap(),
|
||||
Some(ns) if *ns == "style" => {
|
||||
el.dyn_ref::<HtmlElement>()
|
||||
.map(|f| f.style().set_property(name, value));
|
||||
}
|
||||
Some(ns) => el.set_attribute_ns(Some(ns), name, value).unwrap(),
|
||||
None => el.set_attribute(name, value).unwrap(),
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
||||
use core::panic;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
let window = web_sys::window().unwrap();
|
||||
|
||||
let protocol = if window.location().protocol().unwrap() == "https:" {
|
||||
"wss:"
|
||||
} else {
|
||||
"ws:"
|
||||
let protocol = match window.location().protocol().unwrap() {
|
||||
prot if prot == "https:" => "wss:",
|
||||
_ => "ws:",
|
||||
};
|
||||
|
||||
let url = format!(
|
||||
@@ -43,10 +43,11 @@ pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
||||
if let Ok(text) = e.data().dyn_into::<js_sys::JsString>() {
|
||||
let text: Result<String, _> = text.try_into();
|
||||
if let Ok(string) = text {
|
||||
match serde_json::from_str(Box::leak(string.into_boxed_str())) {
|
||||
Ok(template) => _ = tx.unbounded_send(template),
|
||||
Err(e) => panic!("Failed to parse template: {}", e),
|
||||
}
|
||||
let val = serde_json::from_str::<serde_json::Value>(&string).unwrap();
|
||||
// leak the value
|
||||
let val: &'static serde_json::Value = Box::leak(Box::new(val));
|
||||
let template: Template<'_> = Template::deserialize(val).unwrap();
|
||||
tx.unbounded_send(template).unwrap();
|
||||
}
|
||||
}
|
||||
}) as Box<dyn FnMut(MessageEvent)>);
|
||||
|
||||
Reference in new issue
Block a user