Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / iron-meta / iron-meta-extracted.js
blobe9a74f079a44278c405b63eaf037751f83485b07
3 (function() {
5 // monostate data
6 var metaDatas = {};
7 var metaArrays = {};
9 Polymer.IronMeta = Polymer({
11 is: 'iron-meta',
13 properties: {
15 /**
16 * The type of meta-data. All meta-data of the same type is stored
17 * together.
19 type: {
20 type: String,
21 value: 'default',
22 observer: '_typeChanged'
25 /**
26 * The key used to store `value` under the `type` namespace.
28 key: {
29 type: String,
30 observer: '_keyChanged'
33 /**
34 * The meta-data to store or retrieve.
36 value: {
37 type: Object,
38 notify: true,
39 observer: '_valueChanged'
42 /**
43 * If true, `value` is set to the iron-meta instance itself.
45 self: {
46 type: Boolean,
47 observer: '_selfChanged'
50 /**
51 * Array of all meta-data values for the given type.
53 list: {
54 type: Array,
55 notify: true
60 /**
61 * Only runs if someone invokes the factory/constructor directly
62 * e.g. `new Polymer.IronMeta()`
64 factoryImpl: function(config) {
65 if (config) {
66 for (var n in config) {
67 switch(n) {
68 case 'type':
69 case 'key':
70 case 'value':
71 this[n] = config[n];
72 break;
78 created: function() {
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) {
93 if (self) {
94 this.value = this;
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.
114 * @method byKey
115 * @param {string} key The key of the meta-data to be returned.
116 * @return {*}
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) {
137 data[key] = value;
138 list.push(value);
142 _unregister: function(key, data, list) {
143 if (key && data) {
144 if (key in data) {
145 var value = data[key];
146 delete data[key];
147 this.arrayDelete(list, value);
155 `iron-meta-query` can be used to access infomation stored in `iron-meta`.
157 Examples:
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',
177 properties: {
180 * The type of meta-data. All meta-data of the same type is stored
181 * together.
183 type: {
184 type: String,
185 value: 'default',
186 observer: '_typeChanged'
190 * Specifies a key to use for retrieving `value` from the `type`
191 * namespace.
193 key: {
194 type: String,
195 observer: '_keyChanged'
199 * The meta-data to store or retrieve.
201 value: {
202 type: Object,
203 notify: true,
204 readOnly: true
208 * Array of all meta-data values for the given type.
210 list: {
211 type: Array,
212 notify: true
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) {
222 if (config) {
223 for (var n in config) {
224 switch(n) {
225 case 'type':
226 case 'key':
227 this[n] = config[n];
228 break;
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];
247 if (this.key) {
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.
255 * @return {*}
257 byKey: function(key) {
258 return this._metaData && this._metaData[key];
263 })();