-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swap resize controller and resize controller for root names
- Loading branch information
Dima Voytenko
committed
Jan 6, 2021
1 parent
2d34687
commit 62d5ae3
Showing
6 changed files
with
301 additions
and
301 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import ResizeObserverController from './ResizeObserverController.js'; | ||
|
||
/** | ||
* Singleton controller class which handles updates of ResizeObserver instances. | ||
*/ | ||
export default class GlobalResizeObserverController { | ||
/** | ||
* QQQ | ||
* | ||
* @private {Map<Node, ResizeObserverController>} | ||
*/ | ||
rootNodeControllers_ = typeof WeakMap !== 'undefined' ? new WeakMap() : new Map(); | ||
|
||
/** | ||
* Holds reference to the controller's instance. | ||
* | ||
* @private {GlobalResizeObserverController} | ||
*/ | ||
static instance_ = null; | ||
|
||
/** | ||
* Adds observer to observers list. | ||
* | ||
* @param {Node} rootNode - QQQ | ||
* @param {ResizeObserverSPI} observer - Observer to be added. | ||
* @returns {void} | ||
*/ | ||
addObserver(rootNode, observer) { | ||
let rootNodeController = this.rootNodeControllers_.get(rootNode); | ||
|
||
if (!rootNodeController) { | ||
rootNodeController = new ResizeObserverController(rootNode); | ||
this.rootNodeControllers_.set(rootNode, rootNodeController); | ||
} | ||
rootNodeController.addObserver(observer); | ||
} | ||
|
||
/** | ||
* Removes observer from observers list. | ||
* | ||
* @param {Node} rootNode - QQQ | ||
* @param {ResizeObserverSPI} observer - Observer to be removed. | ||
* @returns {void} | ||
*/ | ||
removeObserver(rootNode, observer) { | ||
const rootNodeController = this.rootNodeControllers_.get(rootNode); | ||
|
||
if (rootNodeController) { | ||
rootNodeController.removeObserver(observer); | ||
} | ||
} | ||
|
||
/** | ||
* Invokes the update of observers. It will continue running updates insofar | ||
* it detects changes. | ||
* | ||
* @param {Node} rootNode - QQQ | ||
* @returns {void} | ||
*/ | ||
refresh(rootNode) { | ||
const rootNodeController = this.rootNodeControllers_.get(rootNode); | ||
|
||
if (rootNodeController) { | ||
rootNodeController.refresh(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns instance of the GlobalResizeObserverController. | ||
* | ||
* @returns {GlobalResizeObserverController} | ||
*/ | ||
static getInstance() { | ||
if (!this.instance_) { | ||
this.instance_ = new GlobalResizeObserverController(); | ||
} | ||
|
||
return this.instance_; | ||
} | ||
} |
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
Oops, something went wrong.