Last active
June 28, 2017 14:16
-
-
Save lukaskleinschmidt/a422792a3f4c31ad7ed2a6c794b707d5 to your computer and use it in GitHub Desktop.
javscript components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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