diff options
Diffstat (limited to 'js/dist/dom/data.js')
-rw-r--r-- | js/dist/dom/data.js | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/js/dist/dom/data.js b/js/dist/dom/data.js index 03de237520..180d404f3c 100644 --- a/js/dist/dom/data.js +++ b/js/dist/dom/data.js @@ -1,5 +1,5 @@ /*! - * Bootstrap data.js v5.0.0-beta2 (https://getbootstrap.com/) + * Bootstrap data.js v5.0.0-beta3 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ @@ -11,7 +11,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta2): dom/data.js + * Bootstrap (v5.0.0-beta3): dom/data.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -21,62 +21,49 @@ * Constants * ------------------------------------------------------------------------ */ - var mapData = function () { - var storeData = {}; - var id = 1; - return { - set: function set(element, key, data) { - if (typeof element.bsKey === 'undefined') { - element.bsKey = { - key: key, - id: id - }; - id++; - } + const elementMap = new Map(); + var data = { + set(element, key, instance) { + if (!elementMap.has(element)) { + elementMap.set(element, new Map()); + } - storeData[element.bsKey.id] = data; - }, - get: function get(element, key) { - if (!element || typeof element.bsKey === 'undefined') { - return null; - } + const instanceMap = elementMap.get(element); // make it clear we only want one instance per element + // can be removed later when multiple key/instances are fine to be used - var keyProperties = element.bsKey; + if (!instanceMap.has(key) && instanceMap.size !== 0) { + // eslint-disable-next-line no-console + console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`); + return; + } - if (keyProperties.key === key) { - return storeData[keyProperties.id]; - } + instanceMap.set(key, instance); + }, - return null; - }, - delete: function _delete(element, key) { - if (typeof element.bsKey === 'undefined') { - return; - } + get(element, key) { + if (elementMap.has(element)) { + return elementMap.get(element).get(key) || null; + } - var keyProperties = element.bsKey; + return null; + }, - if (keyProperties.key === key) { - delete storeData[keyProperties.id]; - delete element.bsKey; - } + remove(element, key) { + if (!elementMap.has(element)) { + return; } - }; - }(); - var Data = { - setData: function setData(instance, key, data) { - mapData.set(instance, key, data); - }, - getData: function getData(instance, key) { - return mapData.get(instance, key); - }, - removeData: function removeData(instance, key) { - mapData.delete(instance, key); + const instanceMap = elementMap.get(element); + instanceMap.delete(key); // free up element references if there are no instances left for an element + + if (instanceMap.size === 0) { + elementMap.delete(element); + } } + }; - return Data; + return data; }))); //# sourceMappingURL=data.js.map |