7 Polymer
.IronMeta
= Polymer({
14 * The type of meta-data. All meta-data of the same type is stored
20 observer
: '_typeChanged'
24 * The key used to store `value` under the `type` namespace.
28 observer
: '_keyChanged'
32 * The meta-data to store or retrieve.
37 observer
: '_valueChanged'
41 * If true, `value` is set to the iron-meta instance itself.
45 observer
: '_selfChanged'
49 * Array of all meta-data values for the given type.
59 * Only runs if someone invokes the factory/constructor directly
60 * e.g. `new Polymer.IronMeta()`
62 factoryImpl: function(config
) {
64 for (var n
in config
) {
77 // TODO(sjmiles): good for debugging?
78 this._metaDatas
= metaDatas
;
79 this._metaArrays
= metaArrays
;
82 _keyChanged: function(key
, old
) {
83 this._resetRegistration(old
);
86 _valueChanged: function(value
) {
87 this._resetRegistration(this.key
);
90 _selfChanged: function(self
) {
96 _typeChanged: function(type
) {
97 this._unregisterKey(this.key
);
98 if (!metaDatas
[type
]) {
101 this._metaData
= metaDatas
[type
];
102 if (!metaArrays
[type
]) {
103 metaArrays
[type
] = [];
105 this.list
= metaArrays
[type
];
106 this._registerKeyValue(this.key
, this.value
);
110 * Retrieves meta data value by key.
113 * @param {string} key The key of the meta-data to be returned.
116 byKey: function(key
) {
117 return this._metaData
&& this._metaData
[key
];
120 _resetRegistration: function(oldKey
) {
121 this._unregisterKey(oldKey
);
122 this._registerKeyValue(this.key
, this.value
);
125 _unregisterKey: function(key
) {
126 this._unregister(key
, this._metaData
, this.list
);
129 _registerKeyValue: function(key
, value
) {
130 this._register(key
, value
, this._metaData
, this.list
);
133 _register: function(key
, value
, data
, list
) {
134 if (key
&& data
&& value
!== undefined) {
140 _unregister: function(key
, data
, list
) {
143 var value
= data
[key
];
145 this.arrayDelete(list
, value
);
153 `iron-meta-query` can be used to access infomation stored in `iron-meta`.
157 If I create an instance like this:
159 <iron-meta key="info" value="foo/bar"></iron-meta>
161 Note that value="foo/bar" is the metadata I've defined. I could define more
162 attributes or use child nodes to define additional metadata.
164 Now I can access that element (and it's metadata) from any `iron-meta-query` instance:
166 var value = new Polymer.IronMetaQuery({key: 'info'}).value;
168 @group Polymer Iron Elements
169 @element iron-meta-query
171 Polymer
.IronMetaQuery
= Polymer({
173 is
: 'iron-meta-query',
178 * The type of meta-data. All meta-data of the same type is stored
184 observer
: '_typeChanged'
188 * Specifies a key to use for retrieving `value` from the `type`
193 observer
: '_keyChanged'
197 * The meta-data to store or retrieve.
206 * Array of all meta-data values for the given type.
216 * Actually a factory method, not a true constructor. Only runs if
217 * someone invokes it directly (via `new Polymer.IronMeta()`);
219 factoryImpl: function(config
) {
221 for (var n
in config
) {
232 created: function() {
233 // TODO(sjmiles): good for debugging?
234 this._metaDatas
= metaDatas
;
235 this._metaArrays
= metaArrays
;
238 _keyChanged: function(key
) {
239 this._setValue(this._metaData
&& this._metaData
[key
]);
242 _typeChanged: function(type
) {
243 this._metaData
= metaDatas
[type
];
244 this.list
= metaArrays
[type
];
246 this._keyChanged(this.key
);
251 * Retrieves meta data value by key.
252 * @param {string} key The key of the meta-data to be returned.
255 byKey: function(key
) {
256 return this._metaData
&& this._metaData
[key
];