resize-observer-polyfill
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
/** | ||
@@ -228,2 +226,8 @@ * Exports global object for the current environment. | ||
// Minimum delay before invoking the update of observers. | ||
var REFRESH_DELAY = 20; | ||
// Delay before the next iteration of the continuous cycle. | ||
var CONTINUOUS_DELAY = 80; | ||
// Define whether the MutationObserver is supported. | ||
@@ -238,8 +242,2 @@ // eslint-disable-next-line no-extra-parens | ||
// Minimum delay before invoking the update of observers. | ||
var REFRESH_DELAY = 20; | ||
// Delay before iteration of the continuous cycle. | ||
var CONTINUOUS_HANDLER_DELAY = 80; | ||
/** | ||
@@ -257,3 +255,3 @@ * Controller class which handles updates of ResizeObserver instances. | ||
*/ | ||
var ResizeObserverController = function () { | ||
var ResizeObserverController = function() { | ||
/** | ||
@@ -274,2 +272,9 @@ * Continuous updates must be enabled if MutationObserver is not supported. | ||
/** | ||
* Keeps reference to the instance of MutationObserver. | ||
* | ||
* @private {MutationObserver} | ||
*/ | ||
this.mutationsObserver_ = null; | ||
/** | ||
* A list of connected observers. | ||
@@ -286,3 +291,3 @@ * | ||
// Additionally postpone invocation of the continuous updates. | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_HANDLER_DELAY); | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_DELAY); | ||
}; | ||
@@ -366,20 +371,15 @@ | ||
ResizeObserverController.prototype.updateObservers_ = function () { | ||
var hasChanges = false; | ||
// Collect observers that have active entries. | ||
var active = this.observers_.filter(function (observer) { | ||
return observer.gatherActive(), observer.hasActive(); | ||
}); | ||
for (var i = 0, list = this.observers_; i < list.length; i += 1) { | ||
// Collect active observations. | ||
var observer = list[i]; | ||
// Deliver notifications in a separate cycle in order to avoid any | ||
// collisions between observers. E.g. when multiple instances of | ||
// ResizeObserer are tracking the same element and the callback of one | ||
// of them changes content dimensions of the observed target. Sometimes | ||
// this may result in notifications being blocked for the rest of observers. | ||
active.forEach(function (observer) { return observer.broadcastActive(); }); | ||
observer.gatherActive(); | ||
// Broadcast active observations and set the flag that changes have | ||
// been detected. | ||
if (observer.hasActive()) { | ||
hasChanges = true; | ||
observer.broadcastActive(); | ||
} | ||
} | ||
return hasChanges; | ||
return active.length > 0; | ||
}; | ||
@@ -910,3 +910,3 @@ | ||
if (!targets.size) { | ||
this.disconnect(); | ||
this.controller_.disconnect(this); | ||
} | ||
@@ -984,3 +984,3 @@ }; | ||
ResizeObserverSPI.prototype.hasActive = function () { | ||
return !!this.activeTargets_.length; | ||
return this.activeTargets_.length > 0; | ||
}; | ||
@@ -987,0 +987,0 @@ |
@@ -233,2 +233,8 @@ (function (global, factory) { | ||
// Minimum delay before invoking the update of observers. | ||
var REFRESH_DELAY = 20; | ||
// Delay before the next iteration of the continuous cycle. | ||
var CONTINUOUS_DELAY = 80; | ||
// Define whether the MutationObserver is supported. | ||
@@ -243,8 +249,2 @@ // eslint-disable-next-line no-extra-parens | ||
// Minimum delay before invoking the update of observers. | ||
var REFRESH_DELAY = 20; | ||
// Delay before iteration of the continuous cycle. | ||
var CONTINUOUS_HANDLER_DELAY = 80; | ||
/** | ||
@@ -262,3 +262,3 @@ * Controller class which handles updates of ResizeObserver instances. | ||
*/ | ||
var ResizeObserverController = function () { | ||
var ResizeObserverController = function() { | ||
/** | ||
@@ -279,2 +279,9 @@ * Continuous updates must be enabled if MutationObserver is not supported. | ||
/** | ||
* Keeps reference to the instance of MutationObserver. | ||
* | ||
* @private {MutationObserver} | ||
*/ | ||
this.mutationsObserver_ = null; | ||
/** | ||
* A list of connected observers. | ||
@@ -291,3 +298,3 @@ * | ||
// Additionally postpone invocation of the continuous updates. | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_HANDLER_DELAY); | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_DELAY); | ||
}; | ||
@@ -371,20 +378,15 @@ | ||
ResizeObserverController.prototype.updateObservers_ = function () { | ||
var hasChanges = false; | ||
// Collect observers that have active entries. | ||
var active = this.observers_.filter(function (observer) { | ||
return observer.gatherActive(), observer.hasActive(); | ||
}); | ||
for (var i = 0, list = this.observers_; i < list.length; i += 1) { | ||
// Collect active observations. | ||
var observer = list[i]; | ||
// Deliver notifications in a separate cycle in order to avoid any | ||
// collisions between observers. E.g. when multiple instances of | ||
// ResizeObserer are tracking the same element and the callback of one | ||
// of them changes content dimensions of the observed target. Sometimes | ||
// this may result in notifications being blocked for the rest of observers. | ||
active.forEach(function (observer) { return observer.broadcastActive(); }); | ||
observer.gatherActive(); | ||
// Broadcast active observations and set the flag that changes have | ||
// been detected. | ||
if (observer.hasActive()) { | ||
hasChanges = true; | ||
observer.broadcastActive(); | ||
} | ||
} | ||
return hasChanges; | ||
return active.length > 0; | ||
}; | ||
@@ -915,3 +917,3 @@ | ||
if (!targets.size) { | ||
this.disconnect(); | ||
this.controller_.disconnect(this); | ||
} | ||
@@ -989,3 +991,3 @@ }; | ||
ResizeObserverSPI.prototype.hasActive = function () { | ||
return !!this.activeTargets_.length; | ||
return this.activeTargets_.length > 0; | ||
}; | ||
@@ -992,0 +994,0 @@ |
@@ -233,2 +233,8 @@ (function (global, factory) { | ||
// Minimum delay before invoking the update of observers. | ||
var REFRESH_DELAY = 20; | ||
// Delay before the next iteration of the continuous cycle. | ||
var CONTINUOUS_DELAY = 80; | ||
// Define whether the MutationObserver is supported. | ||
@@ -243,8 +249,2 @@ // eslint-disable-next-line no-extra-parens | ||
// Minimum delay before invoking the update of observers. | ||
var REFRESH_DELAY = 20; | ||
// Delay before iteration of the continuous cycle. | ||
var CONTINUOUS_HANDLER_DELAY = 80; | ||
/** | ||
@@ -262,3 +262,3 @@ * Controller class which handles updates of ResizeObserver instances. | ||
*/ | ||
var ResizeObserverController = function () { | ||
var ResizeObserverController = function() { | ||
/** | ||
@@ -279,2 +279,9 @@ * Continuous updates must be enabled if MutationObserver is not supported. | ||
/** | ||
* Keeps reference to the instance of MutationObserver. | ||
* | ||
* @private {MutationObserver} | ||
*/ | ||
this.mutationsObserver_ = null; | ||
/** | ||
* A list of connected observers. | ||
@@ -291,3 +298,3 @@ * | ||
// Additionally postpone invocation of the continuous updates. | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_HANDLER_DELAY); | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_DELAY); | ||
}; | ||
@@ -371,20 +378,15 @@ | ||
ResizeObserverController.prototype.updateObservers_ = function () { | ||
var hasChanges = false; | ||
// Collect observers that have active entries. | ||
var active = this.observers_.filter(function (observer) { | ||
return observer.gatherActive(), observer.hasActive(); | ||
}); | ||
for (var i = 0, list = this.observers_; i < list.length; i += 1) { | ||
// Collect active observations. | ||
var observer = list[i]; | ||
// Deliver notifications in a separate cycle in order to avoid any | ||
// collisions between observers. E.g. when multiple instances of | ||
// ResizeObserer are tracking the same element and the callback of one | ||
// of them changes content dimensions of the observed target. Sometimes | ||
// this may result in notifications being blocked for the rest of observers. | ||
active.forEach(function (observer) { return observer.broadcastActive(); }); | ||
observer.gatherActive(); | ||
// Broadcast active observations and set the flag that changes have | ||
// been detected. | ||
if (observer.hasActive()) { | ||
hasChanges = true; | ||
observer.broadcastActive(); | ||
} | ||
} | ||
return hasChanges; | ||
return active.length > 0; | ||
}; | ||
@@ -915,3 +917,3 @@ | ||
if (!targets.size) { | ||
this.disconnect(); | ||
this.controller_.disconnect(this); | ||
} | ||
@@ -989,3 +991,3 @@ }; | ||
ResizeObserverSPI.prototype.hasActive = function () { | ||
return !!this.activeTargets_.length; | ||
return this.activeTargets_.length > 0; | ||
}; | ||
@@ -992,0 +994,0 @@ |
{ | ||
"name": "resize-observer-polyfill", | ||
"author": "Denis Rul <que.etc@gmail.com>", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A polyfill for the Resize Observer API", | ||
@@ -6,0 +6,0 @@ "main": "dist/ResizeObserver.js", |
@@ -46,3 +46,3 @@ ResizeObserver Polyfill | ||
It's recommended to use this library in the form of the [ponyfill](https://github.com/sindresorhus/ponyfill), which doesn't inflict modifications of the global object. | ||
It's recommended to use this library in the form of a [ponyfill](https://github.com/sindresorhus/ponyfill), which doesn't inflict modifications of the global object. | ||
@@ -49,0 +49,0 @@ ```javascript |
import isBrowser from './utils/isBrowser'; | ||
import throttle from './utils/throttle'; | ||
// Minimum delay before invoking the update of observers. | ||
const REFRESH_DELAY = 20; | ||
// Delay before the next iteration of the continuous cycle. | ||
const CONTINUOUS_DELAY = 80; | ||
// Define whether the MutationObserver is supported. | ||
// eslint-disable-next-line no-extra-parens | ||
const mutationsSupported = ( | ||
typeof MutationObserver === 'function' && | ||
typeof MutationObserver == 'function' && | ||
// MutationObserver should not be used if running in IE11 as it's | ||
@@ -12,3 +18,3 @@ // implementation is unreliable. Example: https://jsfiddle.net/x2r3jpuz/2/ | ||
// userAgent's information. | ||
typeof navigator === 'object' && | ||
typeof navigator == 'object' && | ||
!( | ||
@@ -20,8 +26,2 @@ navigator.appName === 'Netscape' && | ||
// Minimum delay before invoking the update of observers. | ||
const REFRESH_DELAY = 20; | ||
// Delay before iteration of the continuous cycle. | ||
const CONTINUOUS_HANDLER_DELAY = 80; | ||
/** | ||
@@ -59,3 +59,3 @@ * Controller class which handles updates of ResizeObserver instances. | ||
*/ | ||
mutationsObserver_; | ||
mutationsObserver_ = null; | ||
@@ -78,3 +78,3 @@ /** | ||
// Additionally postpone invocation of the continuous updates. | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_HANDLER_DELAY); | ||
this.continuousUpdateHandler_ = throttle(this.refresh, CONTINUOUS_DELAY); | ||
} | ||
@@ -158,18 +158,15 @@ | ||
updateObservers_() { | ||
let hasChanges = false; | ||
// Collect observers that have active entries. | ||
const active = this.observers_.filter(observer => { | ||
return observer.gatherActive(), observer.hasActive(); | ||
}); | ||
for (const observer of this.observers_) { | ||
// Collect active observations. | ||
observer.gatherActive(); | ||
// Deliver notifications in a separate cycle in order to avoid any | ||
// collisions between observers. E.g. when multiple instances of | ||
// ResizeObserer are tracking the same element and the callback of one | ||
// of them changes content dimensions of the observed target. Sometimes | ||
// this may result in notifications being blocked for the rest of observers. | ||
active.forEach(observer => observer.broadcastActive()); | ||
// Broadcast active observations and set the flag that changes have | ||
// been detected. | ||
if (observer.hasActive()) { | ||
hasChanges = true; | ||
observer.broadcastActive(); | ||
} | ||
} | ||
return hasChanges; | ||
return active.length > 0; | ||
} | ||
@@ -176,0 +173,0 @@ |
@@ -142,3 +142,3 @@ import {Map} from './shims/es6-collections'; | ||
if (!targets.size) { | ||
this.disconnect(); | ||
this.controller_.disconnect(this); | ||
} | ||
@@ -219,4 +219,4 @@ } | ||
hasActive() { | ||
return !!this.activeTargets_.length; | ||
return this.activeTargets_.length > 0; | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
137723
3595
0