create features for large web-sys events/types
This commit is contained in:
1 parent
cfd62e274e
commit
45d386810b
6 files changed
+107
-107
No files matched your search
@@ -10,16 +10,16 @@
|
||||
use dioxus_core::{
|
||||
BorrowedAttributeValue, ElementId, Mutation, Template, TemplateAttribute, TemplateNode,
|
||||
};
|
||||
use dioxus_html::{event_bubbles, CompositionData, FileEngine, FormData, MountedData};
|
||||
use dioxus_html::{event_bubbles, CompositionData, FormData, MountedData};
|
||||
use dioxus_interpreter_js::{get_node, minimal_bindings, save_template, Channel};
|
||||
use futures_channel::mpsc;
|
||||
use js_sys::Array;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::{any::Any, rc::Rc, sync::Arc};
|
||||
use std::{any::Any, rc::Rc};
|
||||
use wasm_bindgen::{closure::Closure, prelude::wasm_bindgen, JsCast, JsValue};
|
||||
use web_sys::{Document, Element, Event};
|
||||
|
||||
use crate::{file_engine::WebFileEngine, Config};
|
||||
use crate::Config;
|
||||
|
||||
pub struct WebsysDom {
|
||||
document: Document,
|
||||
@@ -385,11 +385,15 @@ fn read_input_to_data(target: Element) -> Rc<FormData> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "file_engine"))]
|
||||
let files = None;
|
||||
#[cfg(feature = "file_engine")]
|
||||
let files = target
|
||||
.dyn_ref()
|
||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||
input.files().and_then(|files| {
|
||||
WebFileEngine::new(files).map(|f| Arc::new(f) as Arc<dyn FileEngine>)
|
||||
crate::file_engine::WebFileEngine::new(files)
|
||||
.map(|f| std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>)
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -3,22 +3,12 @@
|
||||
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<Template<'static>> {
|
||||
let (tx, rx) = futures_channel::mpsc::unbounded();
|
||||
|
||||
std::mem::forget(tx);
|
||||
|
||||
rx
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub(crate) fn init() -> UnboundedReceiver<Template<'static>> {
|
||||
use std::convert::TryInto;
|
||||
use wasm_bindgen::closure::Closure;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{MessageEvent, WebSocket};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
|
||||
+31
-10
@@ -55,13 +55,19 @@
|
||||
|
||||
pub use crate::cfg::Config;
|
||||
use dioxus_core::{Element, Scope, VirtualDom};
|
||||
use futures_util::{pin_mut, FutureExt, StreamExt};
|
||||
use futures_util::{
|
||||
future::{select, Either},
|
||||
pin_mut, FutureExt, StreamExt,
|
||||
};
|
||||
|
||||
mod cache;
|
||||
mod cfg;
|
||||
mod dom;
|
||||
#[cfg(feature = "eval")]
|
||||
mod eval;
|
||||
#[cfg(feature = "file_engine")]
|
||||
mod file_engine;
|
||||
#[cfg(all(feature = "hot_reload", debug_assertions))]
|
||||
mod hot_reload;
|
||||
#[cfg(feature = "hydrate")]
|
||||
mod rehydrate;
|
||||
@@ -167,15 +173,19 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
||||
|
||||
let mut dom = VirtualDom::new_with_props(root, root_props);
|
||||
|
||||
// Eval
|
||||
let cx = dom.base_scope();
|
||||
eval::init_eval(cx);
|
||||
#[cfg(feature = "eval")]
|
||||
{
|
||||
// Eval
|
||||
let cx = dom.base_scope();
|
||||
eval::init_eval(cx);
|
||||
}
|
||||
|
||||
#[cfg(feature = "panic_hook")]
|
||||
if cfg.default_panic_hook {
|
||||
console_error_panic_hook::set_once();
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "hot_reload", debug_assertions))]
|
||||
let mut hotreload_rx = hot_reload::init();
|
||||
|
||||
for s in crate::cache::BUILTIN_INTERNED_STRINGS {
|
||||
@@ -237,12 +247,23 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
||||
let work = dom.wait_for_work().fuse();
|
||||
pin_mut!(work);
|
||||
|
||||
futures_util::select! {
|
||||
_ = work => (None, None),
|
||||
new_template = hotreload_rx.next() => {
|
||||
(None, new_template)
|
||||
}
|
||||
evt = rx.next() => (evt, None)
|
||||
#[cfg(all(feature = "hot_reload", debug_assertions))]
|
||||
// futures_util::select! {
|
||||
// _ = work => (None, None),
|
||||
// new_template = hotreload_rx.next() => {
|
||||
// (None, new_template)
|
||||
// }
|
||||
// evt = rx.next() =>
|
||||
// }
|
||||
match select(work, select(hotreload_rx.next(), rx.next())).await {
|
||||
Either::Left((_, _)) => (None, None),
|
||||
Either::Right((Either::Left((new_template, _)), _)) => (None, new_template),
|
||||
Either::Right((Either::Right((evt, _)), _)) => (evt, None),
|
||||
}
|
||||
#[cfg(not(all(feature = "hot_reload", debug_assertions)))]
|
||||
match select(work, rx.next()).await {
|
||||
Either::Left((_, _)) => (None, None),
|
||||
Either::Right((evt, _)) => (evt, None),
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user