Adding in nightly feature and new events::Event type

This commit is contained in:
Pauan 2021-05-28 00:17:42 +02:00
parent 089a073913
commit bbc3e3a68e
4 changed files with 39 additions and 0 deletions

View File

@ -14,6 +14,7 @@ edition = "2018"
[features]
# TODO should this enable interning ?
default = ["wasm-bindgen/enable-interning"]
nightly = []
[dependencies]
lazy_static = "1.3.0"

View File

@ -265,11 +265,13 @@ impl Dom {
#[inline]
fn create_element<A>(name: &str) -> A where A: JsCast {
// TODO use unchecked_into in release mode ?
bindings::create_element(intern(name)).dyn_into().unwrap_throw()
}
#[inline]
fn create_element_ns<A>(name: &str, namespace: &str) -> A where A: JsCast {
// TODO use unchecked_into in release mode ?
bindings::create_element_ns(intern(namespace), intern(name)).dyn_into().unwrap_throw()
}

View File

@ -3,6 +3,39 @@ use wasm_bindgen::JsCast;
use web_sys::{EventTarget, HtmlInputElement, HtmlTextAreaElement};
#[cfg(feature = "nightly")]
pub struct Event<const NAME: &'static str, T> {
event: T,
}
#[cfg(feature = "nightly")]
impl<T, const NAME: &'static str> StaticEvent for Event<NAME, T> where T: JsCast {
const EVENT_TYPE: &'static str = NAME;
#[inline]
fn unchecked_from_event(event: web_sys::Event) -> Self {
Self {
// TODO use unchecked_into in release mode ?
event: event.dyn_into().unwrap(),
}
}
}
// TODO code duplication
// TODO implement the rest of the methods
#[cfg(feature = "nightly")]
impl<T, const NAME: &'static str> Event<NAME, T> where T: AsRef<web_sys::Event> {
#[inline] pub fn prevent_default(&self) { self.event.as_ref().prevent_default(); }
#[inline] pub fn target(&self) -> Option<EventTarget> { self.event.as_ref().target() }
#[inline]
pub fn dyn_target<A>(&self) -> Option<A> where A: JsCast {
self.target()?.dyn_into().ok()
}
}
macro_rules! make_event {
($name:ident, $type:literal => $event:path) => {
#[derive(Debug)]

View File

@ -1,6 +1,9 @@
#![warn(unreachable_pub)]
#![deny(warnings)]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
#![cfg_attr(feature = "nightly", feature(const_generics))]
#[macro_use]
mod macros;