Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / iron-meta / iron-meta-extracted.js
blobea81812061b0d17dc90b6a882edfb054fce4a0e2
1 (function() {
3 // monostate data
4 var metaDatas = {};
5 var metaArrays = {};
7 Polymer.IronMeta = Polymer({
9 is: 'iron-meta',
11 properties: {
13 /**
14 * The type of meta-data. All meta-data of the same type is stored
15 * together.
17 type: {
18 type: String,
19 value: 'default',
20 observer: '_typeChanged'
23 /**
24 * The key used to store `value` under the `type` namespace.
26 key: {
27 type: String,
28 observer: '_keyChanged'
31 /**
32 * The meta-data to store or retrieve.
34 value: {
35 type: Object,
36 notify: true,
37 observer: '_valueChanged'
40 /**
41 * If true, `value` is set to the iron-meta instance itself.
43 self: {
44 type: Boolean,
45 observer: '_selfChanged'
48 /**
49 * Array of all meta-data values for the given type.
51 list: {
52 type: Array,
53 notify: true
58 /**
59 * Only runs if someone invokes the factory/constructor directly
60 * e.g. `new Polymer.IronMeta()`
62 factoryImpl: function(config) {
63 if (config) {
64 for (var n in config) {
65 switch(n) {
66 case 'type':
67 case 'key':
68 case 'value':
69 this[n] = config[n];
70 break;
76 created: function() {
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) {
91 if (self) {
92 this.value = this;
96 _typeChanged: function(type) {
97 this._unregisterKey(this.key);
98 if (!metaDatas[type]) {
99 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.
112 * @method byKey
113 * @param {string} key The key of the meta-data to be returned.
114 * @return {*}
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) {
135 data[key] = value;
136 list.push(value);
140 _unregister: function(key, data, list) {
141 if (key && data) {
142 if (key in data) {
143 var value = data[key];
144 delete data[key];
145 this.arrayDelete(list, value);
153 `iron-meta-query` can be used to access infomation stored in `iron-meta`.
155 Examples:
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',
175 properties: {
178 * The type of meta-data. All meta-data of the same type is stored
179 * together.
181 type: {
182 type: String,
183 value: 'default',
184 observer: '_typeChanged'
188 * Specifies a key to use for retrieving `value` from the `type`
189 * namespace.
191 key: {
192 type: String,
193 observer: '_keyChanged'
197 * The meta-data to store or retrieve.
199 value: {
200 type: Object,
201 notify: true,
202 readOnly: true
206 * Array of all meta-data values for the given type.
208 list: {
209 type: Array,
210 notify: true
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) {
220 if (config) {
221 for (var n in config) {
222 switch(n) {
223 case 'type':
224 case 'key':
225 this[n] = config[n];
226 break;
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];
245 if (this.key) {
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.
253 * @return {*}
255 byKey: function(key) {
256 return this._metaData && this._metaData[key];
261 })();