Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing resize event in stdweb ResizeService #1014

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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