Add sample setInterval call
This commit is contained in:
parent
7aecf65a86
commit
a25014ef0d
|
@ -26,6 +26,7 @@ features = [
|
|||
"AudioBuffer",
|
||||
"HtmlCanvasElement",
|
||||
"CanvasRenderingContext2d",
|
||||
"Window",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::agents::audio_agent::{AudioAgent, AudioData};
|
||||
use crate::utils;
|
||||
use std::sync::Arc;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::HtmlCanvasElement;
|
||||
use yew::agent::Bridged;
|
||||
|
@ -12,6 +13,7 @@ pub struct Canvas {
|
|||
_audio_agent: Box<dyn Bridge<AudioAgent>>,
|
||||
canvas_node: NodeRef,
|
||||
audio_data: Option<Arc<AudioData>>,
|
||||
cb: Option<Closure<dyn FnMut()>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -29,6 +31,26 @@ impl Component for Canvas {
|
|||
_audio_agent: AudioAgent::bridge(link.callback(Msg::AudioAgentMessage)),
|
||||
canvas_node: NodeRef::default(),
|
||||
audio_data: None,
|
||||
cb: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn rendered(&mut self, first_render: bool) {
|
||||
if first_render {
|
||||
let cb = Closure::wrap(Box::new(|| {
|
||||
ConsoleService::log(&format!("In the callback"));
|
||||
}) as Box<dyn FnMut()>);
|
||||
|
||||
// TODO: request_animation_frame() ?
|
||||
let window = web_sys::window().unwrap();
|
||||
window
|
||||
.set_interval_with_callback_and_timeout_and_arguments_0(
|
||||
cb.as_ref().unchecked_ref(),
|
||||
1000,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
self.cb = Some(cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue