MCPcopy
hub / github.com/autoNumeric/autoNumeric / _addToGlobalList

Method _addToGlobalList

src/AutoNumeric.js:3620–3639  ·  view source on GitHub ↗

* Add the given object to the global AutoNumeric element list. * * @param {AutoNumeric} autoNumericObject * @private

(autoNumericObject)

Source from the content-addressed store, hash-verified

3618 * @private
3619 */
3620 static _addToGlobalList(autoNumericObject) {
3621 if (!this._doesGlobalListExists()) {
3622 this._createGlobalList();
3623 }
3624
3625 const domElement = autoNumericObject.node();
3626 // This checks if the object is not already in the global list before adding it.
3627 // This could happen if an AutoNumeric element is initialized, then the DOM element is removed directly via `removeChild` (hence the reference does not get removed from the global list), then it get recreated and initialized again
3628 if (this._isInGlobalList(domElement)) {
3629 if (this._getFromGlobalList(domElement) === this) {
3630 // Do not add this AutoNumeric object again since it's already in that global list
3631 return;
3632 } else {
3633 // Print a warning to warn that the domElement already has a reference in the global map (but we cannot for sure starts deleting those old references since they could still be used by another AutoNumeric object)
3634 AutoNumericHelper.warning(`A reference to the DOM element you just initialized already exists in the global AutoNumeric element list. Please make sure to not initialize the same DOM element multiple times.`, autoNumericObject.getSettings().showWarnings);
3635 }
3636 }
3637
3638 window[this.autoNumericGlobalListName].set(domElement, autoNumericObject);
3639 }
3640
3641 /**
3642 * Remove the given object from the global AutoNumeric element list.

Callers 1

constructorMethod · 0.80

Calls 8

_doesGlobalListExistsMethod · 0.95
_createGlobalListMethod · 0.95
_isInGlobalListMethod · 0.95
_getFromGlobalListMethod · 0.95
nodeMethod · 0.80
warningMethod · 0.80
getSettingsMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected