@juggle/resize-observer
Advanced tools
Comparing version 0.3.1 to 0.4.0
const watchers = []; | ||
const events = [ | ||
'resize', | ||
'transitionend', | ||
'animationend', | ||
'animationstart', | ||
'animationiteration', | ||
'keyup', | ||
'keydown', | ||
'mouseup', | ||
'mousedown', | ||
'mouseover', | ||
'blur', | ||
'focus' | ||
]; | ||
const dispatch = () => { | ||
watchers.forEach((watcher) => watcher()); | ||
}; | ||
events.forEach(name => window.addEventListener(name, dispatch, true)); | ||
if ('MutationObserver' in window) { | ||
const observerConfig = { attributes: true, characterData: true, childList: true, subtree: true }; | ||
new MutationObserver(dispatch).observe(document.body, observerConfig); | ||
} | ||
export default class DOMInteractions { | ||
@@ -10,17 +29,1 @@ static watch(callback) { | ||
} | ||
document.addEventListener('keyup', dispatch, true); | ||
document.addEventListener('keydown', dispatch, true); | ||
document.addEventListener('mouseup', dispatch, true); | ||
document.addEventListener('mousedown', dispatch, true); | ||
document.addEventListener('mouseover', dispatch, true); | ||
document.addEventListener('blur', dispatch, true); | ||
document.addEventListener('focus', dispatch, true); | ||
document.addEventListener('transitionend', dispatch, true); | ||
document.addEventListener('animationend', dispatch, true); | ||
document.addEventListener('animationstart', dispatch, true); | ||
document.addEventListener('animationiteration', dispatch, true); | ||
window.addEventListener('resize', dispatch); | ||
if ('MutationObserver' in window) { | ||
const observerConfig = { attributes: true, characterData: true, childList: true, subtree: true }; | ||
new MutationObserver(dispatch).observe(document.body, observerConfig); | ||
} |
{ | ||
"name": "@juggle/resize-observer", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "ResizeObserver - Based on the official draft specification", | ||
@@ -5,0 +5,0 @@ "main": "./lib/ResizeObserver.js", |
type StandardCallback = () => any; | ||
const watchers: StandardCallback[] = []; | ||
const events = [ | ||
// Global Resize | ||
'resize', | ||
// Transitions & Animations | ||
'transitionend', | ||
'animationend', | ||
'animationstart', | ||
'animationiteration', | ||
// Interactions | ||
'keyup', | ||
'keydown', | ||
'mouseup', | ||
'mousedown', | ||
'mouseover', | ||
'blur', | ||
'focus' | ||
]; | ||
// Dispatcher for interactions | ||
const dispatch: StandardCallback = () => { | ||
@@ -8,26 +27,5 @@ watchers.forEach((watcher: StandardCallback) => watcher()); | ||
export default class DOMInteractions { | ||
public static watch (callback: StandardCallback) { | ||
watchers.push(callback); | ||
} | ||
} | ||
// Listen to events | ||
events.forEach(name => window.addEventListener(name, dispatch, true)); | ||
// Listen to interaction | ||
document.addEventListener('keyup', dispatch, true); | ||
document.addEventListener('keydown', dispatch, true); | ||
document.addEventListener('mouseup', dispatch, true); | ||
document.addEventListener('mousedown', dispatch, true); | ||
document.addEventListener('mouseover', dispatch, true); | ||
document.addEventListener('blur', dispatch, true); | ||
document.addEventListener('focus', dispatch, true); | ||
// Listen to transitions and animations | ||
document.addEventListener('transitionend', dispatch, true); | ||
document.addEventListener('animationend', dispatch, true); | ||
document.addEventListener('animationstart', dispatch, true); | ||
document.addEventListener('animationiteration', dispatch, true); | ||
// Listen for window resize | ||
window.addEventListener('resize', dispatch); | ||
// Listen for any other DOM changes which could affect sizes | ||
@@ -37,2 +35,8 @@ if ('MutationObserver' in window) { | ||
new MutationObserver(dispatch).observe(document.body, observerConfig); | ||
} | ||
export default class DOMInteractions { | ||
public static watch (callback: StandardCallback) { | ||
watchers.push(callback); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
474
19799