source: imaps-frontend/node_modules/bootstrap/js/src/dom/data.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * --------------------------------------------------------------------------
3 * Bootstrap dom/data.js
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5 * --------------------------------------------------------------------------
6 */
7
8/**
9 * Constants
10 */
11
12const elementMap = new Map()
13
14export default {
15 set(element, key, instance) {
16 if (!elementMap.has(element)) {
17 elementMap.set(element, new Map())
18 }
19
20 const instanceMap = elementMap.get(element)
21
22 // make it clear we only want one instance per element
23 // can be removed later when multiple key/instances are fine to be used
24 if (!instanceMap.has(key) && instanceMap.size !== 0) {
25 // eslint-disable-next-line no-console
26 console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`)
27 return
28 }
29
30 instanceMap.set(key, instance)
31 },
32
33 get(element, key) {
34 if (elementMap.has(element)) {
35 return elementMap.get(element).get(key) || null
36 }
37
38 return null
39 },
40
41 remove(element, key) {
42 if (!elementMap.has(element)) {
43 return
44 }
45
46 const instanceMap = elementMap.get(element)
47
48 instanceMap.delete(key)
49
50 // free up element references if there are no instances left for an element
51 if (instanceMap.size === 0) {
52 elementMap.delete(element)
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.