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::convert::AsRef;
|
||||
use std::marker::PhantomData;
|
||||
use std::future::Future;
|
||||
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};
|
||||
|
||||
|
||||
pub struct RefFn<A, B, C> where B: ?Sized {
|
||||
pub struct RefFn<A, B, C> where B: ?Sized, C: Fn(&A) -> &B {
|
||||
value: A,
|
||||
callback: C,
|
||||
return_value: PhantomData<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 {
|
||||
value,
|
||||
callback,
|
||||
return_value: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -423,6 +420,15 @@ impl<A> DomBuilder<A> {
|
|||
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]
|
||||
pub fn future<F>(mut self, future: F) -> Self where F: Future<Output = ()> + 'static {
|
||||
self.callbacks.after_remove(DiscardOnDrop::leak(spawn_future(future)));
|
||||
|
|
Loading…
Reference in New Issue