Created
August 26, 2015 19:17
-
-
Save jordaaash/4216415649aab40d7628 to your computer and use it in GitHub Desktop.
Resize mixin for responsive components
This file contains 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
'use strict'; | |
var ResizeMixin, raf; | |
if (typeof window === 'undefined') { | |
ResizeMixin = {}; | |
} | |
else { | |
raf = require('raf'); | |
ResizeMixin = { | |
componentDidMount () { | |
window.addEventListener('resize', this._handleResize, false); | |
}, | |
componentWillUnmount () { | |
window.removeEventListener('resize', this._handleResize, false); | |
}, | |
_handleResize (event) { | |
raf((function () { | |
if (this.isMounted()) { | |
this.handleResize(event); | |
} | |
}).bind(this)); | |
} | |
}; | |
} | |
module.exports = ResizeMixin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment