Adding in global_event_preventable method
This commit is contained in:
parent
ae479b136a
commit
616a7a1baa
14
src/dom.rs
14
src/dom.rs
|
@ -1,6 +1,5 @@
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::convert::AsRef;
|
use std::convert::AsRef;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
|
@ -21,10 +20,9 @@ use crate::operations::{for_each, spawn_future};
|
||||||
use crate::utils::{EventListener, on, on_preventable, ValueDiscard, FnDiscard};
|
use crate::utils::{EventListener, on, on_preventable, ValueDiscard, FnDiscard};
|
||||||
|
|
||||||
|
|
||||||
pub struct RefFn<A, B, C> where B: ?Sized {
|
pub struct RefFn<A, B, C> where B: ?Sized, C: Fn(&A) -> &B {
|
||||||
value: A,
|
value: A,
|
||||||
callback: C,
|
callback: C,
|
||||||
return_value: PhantomData<B>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A, B, C> RefFn<A, B, C> where B: ?Sized, C: Fn(&A) -> &B {
|
impl<A, B, C> RefFn<A, B, C> where B: ?Sized, C: Fn(&A) -> &B {
|
||||||
|
@ -33,7 +31,6 @@ impl<A, B, C> RefFn<A, B, C> where B: ?Sized, C: Fn(&A) -> &B {
|
||||||
Self {
|
Self {
|
||||||
value,
|
value,
|
||||||
callback,
|
callback,
|
||||||
return_value: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,6 +420,15 @@ impl<A> DomBuilder<A> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO add this to the StylesheetBuilder and ClassBuilder too
|
||||||
|
#[inline]
|
||||||
|
pub fn global_event_preventable<T, F>(mut self, listener: F) -> Self
|
||||||
|
where T: StaticEvent,
|
||||||
|
F: FnMut(T) + 'static {
|
||||||
|
self._event_preventable(bindings::window_event_target(), listener);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn future<F>(mut self, future: F) -> Self where F: Future<Output = ()> + 'static {
|
pub fn future<F>(mut self, future: F) -> Self where F: Future<Output = ()> + 'static {
|
||||||
self.callbacks.after_remove(DiscardOnDrop::leak(spawn_future(future)));
|
self.callbacks.after_remove(DiscardOnDrop::leak(spawn_future(future)));
|
||||||
|
|
Loading…
Reference in New Issue