2018-04-06 00:57:36 +00:00
|
|
|
import debounce from 'lodash-es/debounce'
|
2018-04-01 00:42:52 +00:00
|
|
|
|
|
|
|
const DEBOUNCE_DELAY = 700
|
|
|
|
|
|
|
|
const listeners = new Set()
|
|
|
|
|
|
|
|
if (process.browser && process.env.NODE_ENV !== 'production') {
|
|
|
|
window.resizeListeners = listeners
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.browser) {
|
|
|
|
window.addEventListener('resize', debounce(() => {
|
|
|
|
console.log('resize')
|
|
|
|
listeners.forEach(listener => listener())
|
|
|
|
}, DEBOUNCE_DELAY))
|
|
|
|
}
|
|
|
|
|
|
|
|
export function registerResizeListener (listener) {
|
|
|
|
listeners.add(listener)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unregisterResizeListener (listener) {
|
|
|
|
listeners.delete(listener)
|
|
|
|
}
|