• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2
3  (function() {
4
5    var SKIP_ID = 'meta';
6    var metaData = {}, metaArray = {};
7
8    Polymer('core-meta', {
9
10      /**
11       * The type of meta-data.  All meta-data with the same type with be
12       * stored together.
13       *
14       * @attribute type
15       * @type string
16       * @default 'default'
17       */
18      type: 'default',
19
20      alwaysPrepare: true,
21
22      ready: function() {
23        this.register(this.id);
24      },
25
26      get metaArray() {
27        var t = this.type;
28        if (!metaArray[t]) {
29          metaArray[t] = [];
30        }
31        return metaArray[t];
32      },
33
34      get metaData() {
35        var t = this.type;
36        if (!metaData[t]) {
37          metaData[t] = {};
38        }
39        return metaData[t];
40      },
41
42      register: function(id, old) {
43        if (id && id !== SKIP_ID) {
44          this.unregister(this, old);
45          this.metaData[id] = this;
46          this.metaArray.push(this);
47        }
48      },
49
50      unregister: function(meta, id) {
51        delete this.metaData[id || meta.id];
52        var i = this.metaArray.indexOf(meta);
53        if (i >= 0) {
54          this.metaArray.splice(i, 1);
55        }
56      },
57
58      /**
59       * Returns a list of all meta-data elements with the same type.
60       *
61       * @property list
62       * @type array
63       * @default []
64       */
65      get list() {
66        return this.metaArray;
67      },
68
69      /**
70       * Retrieves meta-data by ID.
71       *
72       * @method byId
73       * @param {String} id The ID of the meta-data to be returned.
74       * @returns Returns meta-data.
75       */
76      byId: function(id) {
77        return this.metaData[id];
78      }
79
80    });
81
82  })();
83
84