data.js 1.19 KB
Newer Older
Johann-S's avatar
Johann-S committed
1
2
3
4
5
6
7
8
9
10
11
12
/**
 * --------------------------------------------------------------------------
 * Bootstrap (v4.0.0-beta): dom/data.js
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

const mapData = (() => {
  const storeData    = {}
  return {
    set(element, key, data) {
      let id
13
      if (typeof element.key === 'undefined') {
Johann-S's avatar
Johann-S committed
14
15
16
17
18
19
20
21
22
        element.key = {
          key,
          id
        }
      }

      storeData[id] = data
    },
    get(element, key) {
23
      if (typeof element.key === 'undefined' || element.key !== key) {
Johann-S's avatar
Johann-S committed
24
25
26
27
28
29
        return null
      }
      const keyProperties = element.key
      return storeData[keyProperties.id]
    },
    delete(element, key) {
30
      if (typeof element.key === 'undefined' || element.key !== key) {
Johann-S's avatar
Johann-S committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        return
      }
      const keyProperties = element.key
      delete storeData[keyProperties.id]
    }
  }
})()

const Data = {
  setData(instance, key, data) {
    mapData.set(instance, key, data)
  },
  getData(instance, key) {
    mapData.get(instance, key)
  },
  removeData(instance, key) {
    mapData.delete(instance, key)
  }
}

export default Data