Merge branch 'upstream' into fix-non-str-attributes

This commit is contained in:
Evan Almloff committed 2022-12-28 20:36:57 -06:00
commit 044462876d
52 files changed
+3002 -2852

No files matched your search

+4 -6
View File
@@ -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(),
}
+15 -8
View File
@@ -2,12 +2,13 @@
use futures_channel::mpsc::UnboundedReceiver;
use dioxus_core::Template;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsCast;
use web_sys::{MessageEvent, WebSocket};
#[cfg(not(debug_assertions))]
pub(crate) fn init() -> UnboundedReceiver<String> {
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
let (tx, rx) = futures_channel::mpsc::unbounded();
std::mem::forget(tx);
@@ -16,15 +17,16 @@ pub(crate) fn init() -> UnboundedReceiver<String> {
}
#[cfg(debug_assertions)]
pub(crate) fn init() -> UnboundedReceiver<String> {
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
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!(
@@ -39,8 +41,13 @@ pub(crate) fn init() -> UnboundedReceiver<String> {
// change the rsx when new data is received
let cl = Closure::wrap(Box::new(move |e: MessageEvent| {
if let Ok(text) = e.data().dyn_into::<js_sys::JsString>() {
if let Ok(val) = text.try_into() {
_ = tx.unbounded_send(val);
let text: Result<String, _> = text.try_into();
if let Ok(string) = text {
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)>);
+9 -5
View File
@@ -204,19 +204,23 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
// if virtualdom has nothing, wait for it to have something before requesting idle time
// if there is work then this future resolves immediately.
let mut res = {
let (mut res, template) = {
let work = dom.wait_for_work().fuse();
pin_mut!(work);
futures_util::select! {
_ = work => None,
_new_template = hotreload_rx.next() => {
todo!("Implement hot reload");
_ = work => (None, None),
new_template = hotreload_rx.next() => {
(None, new_template)
}
evt = rx.next() => evt
evt = rx.next() => (evt, None)
}
};
if let Some(template) = template {
dom.replace_template(template);
}
// Dequeue all of the events from the channel in send order
// todo: we should re-order these if possible
while let Some(evt) = res {