diff options
| author | Patrick H. Lauke <[email protected]> | 2021-05-04 12:46:06 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-04 12:46:06 +0100 |
| commit | 8865a8ab1c7157ab81bf49afa62b75f36daee46d (patch) | |
| tree | 97ef78f2ea8e07aab50014176d061fe3c1d49134 /js/dist/dom/data.js | |
| parent | 018ee6a3b50b958ddb49657086cd9168abf5a485 (diff) | |
| parent | 7ea6578773cb1b7f5cfb8fb41321b3fa10349daf (diff) | |
| download | bootstrap-jo-docs-thanks-page.tar.xz bootstrap-jo-docs-thanks-page.zip | |
Merge branch 'main' into jo-docs-thanks-pagejo-docs-thanks-page
Diffstat (limited to 'js/dist/dom/data.js')
| -rw-r--r-- | js/dist/dom/data.js | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/js/dist/dom/data.js b/js/dist/dom/data.js index eb5d99e87..180d404f3 100644 --- a/js/dist/dom/data.js +++ b/js/dist/dom/data.js @@ -1,6 +1,6 @@ /*! - * Bootstrap data.js v5.0.0-alpha3 (https://getbootstrap.com/) - * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) + * 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) */ (function (global, factory) { @@ -11,7 +11,7 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-alpha3): 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 |
