use std::marker::PhantomData;
use wasm_bindgen::JsValue;
use crate::platform::Callback;
impl<A: Into<JsValue>> Callback<A> {
pub fn call1<T: Into<A>>(&self, arg: T) {
if let Some(f) = self.0.borrow().as_ref() {
f.call1(arg.into());
};
}
}
#[derive(Debug)]
pub struct Function<T> {
inner: js_sys::Function,
_arg: PhantomData<T>,
}
impl Function<()> {
pub fn call0(&self) {
drop(self.inner.call0(&JsValue::NULL));
}
}
impl<T: Into<JsValue>> Function<T> {
pub fn call1(&self, arg: T) {
drop(self.inner.call1(&JsValue::NULL, &arg.into()));
}
}
impl<T> From<js_sys::Function> for Function<T> {
fn from(func: js_sys::Function) -> Self {
Self {
inner: func,
_arg: PhantomData,
}
}
}