Skip to content

Instantly share code, notes, and snippets.

@lukaskleinschmidt
Last active June 28, 2017 14:16
Show Gist options
  • Save lukaskleinschmidt/a422792a3f4c31ad7ed2a6c794b707d5 to your computer and use it in GitHub Desktop.
Save lukaskleinschmidt/a422792a3f4c31ad7ed2a6c794b707d5 to your computer and use it in GitHub Desktop.
javscript components
import Component from './component';
export default class Breakpoint extends Component {
init(mediaQueryString) {
const mql = window.matchMedia(mediaQueryString);
const listener = () => this.trigger(mql.matches ? 'match' : 'unmatch', [mql]);
mql.addListener(listener);
this.set('mql', mql);
this.set('listener', listener);
}
check() {
this.get('listener').call();
//return this for chaining
return this;
}
destroy() {
const mql = this.get('mql');
const listener = this.get('listener');
mql.removeListener(listener);
super.destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment