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

Listening for browser resize #98

Closed
alexlafroscia opened this issue Dec 1, 2016 · 5 comments
Closed

Listening for browser resize #98

alexlafroscia opened this issue Dec 1, 2016 · 5 comments

Comments

@alexlafroscia
Copy link

Is there a way to listen for browser resize events through Flexi? Since it's already scheduling tasks on every keyframe to check size changes, I want to avoid adding my own events. However, I couldn't find a public API for listening for this through the device/layout service. What I ended up doing was super-classing device/layout to add an event trigger:

import Ember from 'ember';
import LayoutService from 'flexi/services/device/layout';
import config from '../../config/environment';

const { Evented, get } = Ember;

export default LayoutService.extend(Evented, {
  breakpoints: config.flexi.breakpoints,

  updateResolution() {
    const originalWidth = get(this, 'width');

    this._super(...arguments);

    const newWidth = get(this, 'width');

    if (originalWidth !== newWidth) {
      this.trigger('width-changed');
    }
  }
});

Is there a better way to do this? Or maybe you'd consider adding a feature like this into Flexi itself?

@RobbieTheWagner
Copy link
Member

@alexlafroscia I don't see why we couldn't add it in. Since we are already triggering things when the size changes, should be able to add in some sort of option to pass a function you want to call when that happens. Just not sure what would be the most user friendly way of doing it. Did you have some ideas? @runspired what do you think of something like this?

@alexlafroscia
Copy link
Author

alexlafroscia commented Dec 2, 2016

Did you have some ideas

I definitely like the idea of using Evented and allowing people to subscribe to events if they want it, like the example code I posted. Subscribe and unsubscribe is already the desired mechanics, and Ember.Evented provides an API for that already.

@runspired
Copy link
Collaborator

I've down, I'd rather an event than having you rely on binding to the props on the service.

@alexlafroscia
Copy link
Author

alexlafroscia commented Dec 2, 2016

What events would you want to provide? Probably something like

  • width-changed
  • height-changed
  • resized (either changed)

although maybe not those names? I also thought that you could generate an even for each breakpoint, but that might be over-kill when it's easy enough to listen for the event and then check some property on the service like isDesktop (which is what I'm doing now)

I suppose that maybe just doing width-changed is enough but, since the device/layout service already stores the height info, you might as well issue events for them as well.

@RobbieTheWagner
Copy link
Member

This is now completed in flexi-layouts html-next/flexi-layouts#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants