Skip to content

Instantly share code, notes, and snippets.

@kevzlou7979
Created August 24, 2017 11:30
Show Gist options
  • Save kevzlou7979/559233ae20518821d91c3974b942a214 to your computer and use it in GitHub Desktop.
Save kevzlou7979/559233ae20518821d91c3974b942a214 to your computer and use it in GitHub Desktop.
public class ViewPortManager {
private HandlerRegistration windowResizeHandler;
private List<ViewPortHelper.ViewPort> viewPorts;
public ViewPortManager when(ViewPortHelper.ViewPort... viewPorts) {
this.viewPorts = Arrays.asList(viewPorts);
return this;
}
public void then(Functions.Func callback) {
final boolean[] matches = {false};
viewPorts.forEach(viewPort -> {
if (ViewPortHelper.matchMedia(viewPort)) {
matches[0] = true;
}
});
if (matches[0]) {
callback.call();
}
windowResizeHandler = Window.addResizeHandler(resizeEvent -> {
if (matches[0]) {
callback.call();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment