Skip to content

Commit

Permalink
Fix missing resize event in stdweb ResizeService (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklaswj authored Mar 11, 2020
1 parent 8afeb03 commit a4ad32b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/services/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use yew::callback::Callback;
cfg_if! {
if #[cfg(feature = "std_web")] {
use stdweb::js;
use stdweb::web::{window, Window};
use stdweb::web::{event::ResizeEvent, window, Window};
use stdweb::Value;
} else if #[cfg(feature = "web_sys")] {
use gloo::events::EventListener;
Expand Down Expand Up @@ -64,14 +64,16 @@ impl ResizeService {

/// Register a callback that will be called when the browser window resizes.
pub fn register(&mut self, callback: Callback<WindowDimensions>) -> ResizeTask {
let callback = move |#[cfg(feature = "web_sys")] _event: &Event| {
let window = cfg_match! {
feature = "std_web" => window(),
feature = "web_sys" => web_sys::window().unwrap(),
let callback =
move |#[cfg(feature = "web_sys")] _event: &Event,
#[cfg(feature = "std_web")] _event: ResizeEvent| {
let window = cfg_match! {
feature = "std_web" => window(),
feature = "web_sys" => web_sys::window().unwrap(),
};
let dimensions = WindowDimensions::get_dimensions(&window);
callback.emit(dimensions);
};
let dimensions = WindowDimensions::get_dimensions(&window);
callback.emit(dimensions);
};
let handle = cfg_match! {
feature = "std_web" => js! {
var handle = @{callback};
Expand Down

0 comments on commit a4ad32b

Please sign in to comment.