source: imaps-frontend/node_modules/resize-observer-polyfill/src/ResizeObserver.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import {Map} from './shims/es6-collections.js';
2import ResizeObserverController from './ResizeObserverController.js';
3import ResizeObserverSPI from './ResizeObserverSPI.js';
4
5// Registry of internal observers. If WeakMap is not available use current shim
6// for the Map collection as it has all required methods and because WeakMap
7// can't be fully polyfilled anyway.
8const observers = typeof WeakMap !== 'undefined' ? new WeakMap() : new Map();
9
10/**
11 * ResizeObserver API. Encapsulates the ResizeObserver SPI implementation
12 * exposing only those methods and properties that are defined in the spec.
13 */
14class ResizeObserver {
15 /**
16 * Creates a new instance of ResizeObserver.
17 *
18 * @param {ResizeObserverCallback} callback - Callback that is invoked when
19 * dimensions of the observed elements change.
20 */
21 constructor(callback) {
22 if (!(this instanceof ResizeObserver)) {
23 throw new TypeError('Cannot call a class as a function.');
24 }
25 if (!arguments.length) {
26 throw new TypeError('1 argument required, but only 0 present.');
27 }
28
29 const controller = ResizeObserverController.getInstance();
30 const observer = new ResizeObserverSPI(callback, controller, this);
31
32 observers.set(this, observer);
33 }
34}
35
36// Expose public methods of ResizeObserver.
37[
38 'observe',
39 'unobserve',
40 'disconnect'
41].forEach(method => {
42 ResizeObserver.prototype[method] = function () {
43 return observers.get(this)[method](...arguments);
44 };
45});
46
47export default ResizeObserver;
Note: See TracBrowser for help on using the repository browser.