9 Polymer.IronMeta = Polymer({
16 * The type of meta-data. All meta-data of the same type is stored
22 observer: '_typeChanged'
26 * The key used to store `value` under the `type` namespace.
30 observer: '_keyChanged'
34 * The meta-data to store or retrieve.
39 observer: '_valueChanged'
43 * If true, `value` is set to the iron-meta instance itself.
47 observer: '_selfChanged'
51 * Array of all meta-data values for the given type.
61 * Only runs if someone invokes the factory/constructor directly
62 * e.g. `new Polymer.IronMeta()`
64 factoryImpl: function(config) {
66 for (var n in config) {
79 // TODO(sjmiles): good for debugging?
80 this._metaDatas = metaDatas;
81 this._metaArrays = metaArrays;
84 _keyChanged: function(key, old) {
85 this._resetRegistration(old);
88 _valueChanged: function(value) {
89 this._resetRegistration(this.key);
92 _selfChanged: function(self) {
98 _typeChanged: function(type) {
99 this._unregisterKey(this.key);
100 if (!metaDatas[type]) {
101 metaDatas[type] = {};
103 this._metaData = metaDatas[type];
104 if (!metaArrays[type]) {
105 metaArrays[type] = [];
107 this.list = metaArrays[type];
108 this._registerKeyValue(this.key, this.value);
112 * Retrieves meta data value by key.
115 * @param {string} key The key of the meta-data to be returned.
118 byKey: function(key) {
119 return this._metaData && this._metaData[key];
122 _resetRegistration: function(oldKey) {
123 this._unregisterKey(oldKey);
124 this._registerKeyValue(this.key, this.value);
127 _unregisterKey: function(key) {
128 this._unregister(key, this._metaData, this.list);
131 _registerKeyValue: function(key, value) {
132 this._register(key, value, this._metaData, this.list);
135 _register: function(key, value, data, list) {
136 if (key && data && value !== undefined) {
142 _unregister: function(key, data, list) {
145 var value = data[key];
147 this.arrayDelete(list, value);
155 `iron-meta-query` can be used to access infomation stored in `iron-meta`.
159 If I create an instance like this:
161 <iron-meta key="info" value="foo/bar"></iron-meta>
163 Note that value="foo/bar" is the metadata I've defined. I could define more
164 attributes or use child nodes to define additional metadata.
166 Now I can access that element (and it's metadata) from any `iron-meta-query` instance:
168 var value = new Polymer.IronMetaQuery({key: 'info'}).value;
170 @group Polymer Iron Elements
171 @element iron-meta-query
173 Polymer.IronMetaQuery = Polymer({
175 is: 'iron-meta-query',
180 * The type of meta-data. All meta-data of the same type is stored
186 observer: '_typeChanged'
190 * Specifies a key to use for retrieving `value` from the `type`
195 observer: '_keyChanged'
199 * The meta-data to store or retrieve.
208 * Array of all meta-data values for the given type.
218 * Actually a factory method, not a true constructor. Only runs if
219 * someone invokes it directly (via `new Polymer.IronMeta()`);
221 factoryImpl: function(config) {
223 for (var n in config) {
234 created: function() {
235 // TODO(sjmiles): good for debugging?
236 this._metaDatas = metaDatas;
237 this._metaArrays = metaArrays;
240 _keyChanged: function(key) {
241 this._setValue(this._metaData && this._metaData[key]);
244 _typeChanged: function(type) {
245 this._metaData = metaDatas[type];
246 this.list = metaArrays[type];
248 this._keyChanged(this.key);
253 * Retrieves meta data value by key.
254 * @param {string} key The key of the meta-data to be returned.
257 byKey: function(key) {
258 return this._metaData && this._metaData[key];