OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
9 --> | 9 --> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 If I create an instance like this: | 26 If I create an instance like this: |
27 | 27 |
28 <iron-meta key="info" value="foo/bar"></iron-meta> | 28 <iron-meta key="info" value="foo/bar"></iron-meta> |
29 | 29 |
30 Note that value="foo/bar" is the metadata I've defined. I could define more | 30 Note that value="foo/bar" is the metadata I've defined. I could define more |
31 attributes or use child nodes to define additional metadata. | 31 attributes or use child nodes to define additional metadata. |
32 | 32 |
33 Now I can access that element (and it's metadata) from any iron-meta instance | 33 Now I can access that element (and it's metadata) from any iron-meta instance |
34 via the byKey method, e.g. | 34 via the byKey method, e.g. |
35 | 35 |
36 meta.byKey('info').getAttribute('value'). | 36 meta.byKey('info').getAttribute('value'); |
37 | 37 |
38 Pure imperative form would be like: | 38 Pure imperative form would be like: |
39 | 39 |
40 document.createElement('iron-meta').byKey('info').getAttribute('value'); | 40 document.createElement('iron-meta').byKey('info').getAttribute('value'); |
41 | 41 |
42 Or, in a Polymer element, you can include a meta in your template: | 42 Or, in a Polymer element, you can include a meta in your template: |
43 | 43 |
44 <iron-meta id="meta"></iron-meta> | 44 <iron-meta id="meta"></iron-meta> |
45 ... | 45 ... |
46 this.$.meta.byKey('info').getAttribute('value'); | 46 this.$.meta.byKey('info').getAttribute('value'); |
47 | 47 |
48 @group Iron Elements | 48 @group Iron Elements |
49 @demo demo/index.html | 49 @demo demo/index.html |
50 @hero hero.svg | 50 @hero hero.svg |
51 @element iron-meta | 51 @element iron-meta |
52 --> | 52 --> |
53 | 53 |
54 <script> | 54 <script> |
55 | 55 |
56 (function() { | 56 (function() { |
57 | 57 |
58 // monostate data | 58 // monostate data |
59 var metaDatas = {}; | 59 var metaDatas = {}; |
60 var metaArrays = {}; | 60 var metaArrays = {}; |
| 61 var singleton = null; |
61 | 62 |
62 Polymer.IronMeta = Polymer({ | 63 Polymer.IronMeta = Polymer({ |
63 | 64 |
64 is: 'iron-meta', | 65 is: 'iron-meta', |
65 | 66 |
66 properties: { | 67 properties: { |
67 | 68 |
68 /** | 69 /** |
69 * The type of meta-data. All meta-data of the same type is stored | 70 * The type of meta-data. All meta-data of the same type is stored |
70 * together. | 71 * together. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 /** | 104 /** |
104 * Array of all meta-data values for the given type. | 105 * Array of all meta-data values for the given type. |
105 */ | 106 */ |
106 list: { | 107 list: { |
107 type: Array, | 108 type: Array, |
108 notify: true | 109 notify: true |
109 } | 110 } |
110 | 111 |
111 }, | 112 }, |
112 | 113 |
| 114 hostAttributes: { |
| 115 hidden: true |
| 116 }, |
| 117 |
113 /** | 118 /** |
114 * Only runs if someone invokes the factory/constructor directly | 119 * Only runs if someone invokes the factory/constructor directly |
115 * e.g. `new Polymer.IronMeta()` | 120 * e.g. `new Polymer.IronMeta()` |
| 121 * |
| 122 * @param {{type: (string|undefined), key: (string|undefined), value}=} co
nfig |
116 */ | 123 */ |
117 factoryImpl: function(config) { | 124 factoryImpl: function(config) { |
118 if (config) { | 125 if (config) { |
119 for (var n in config) { | 126 for (var n in config) { |
120 switch(n) { | 127 switch(n) { |
121 case 'type': | 128 case 'type': |
122 case 'key': | 129 case 'key': |
123 case 'value': | 130 case 'value': |
124 this[n] = config[n]; | 131 this[n] = config[n]; |
125 break; | 132 break; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (key in data) { | 204 if (key in data) { |
198 var value = data[key]; | 205 var value = data[key]; |
199 delete data[key]; | 206 delete data[key]; |
200 this.arrayDelete(list, value); | 207 this.arrayDelete(list, value); |
201 } | 208 } |
202 } | 209 } |
203 } | 210 } |
204 | 211 |
205 }); | 212 }); |
206 | 213 |
| 214 Polymer.IronMeta.getIronMeta = function getIronMeta() { |
| 215 if (singleton === null) { |
| 216 singleton = new Polymer.IronMeta(); |
| 217 } |
| 218 return singleton; |
| 219 }; |
| 220 |
207 /** | 221 /** |
208 `iron-meta-query` can be used to access infomation stored in `iron-meta`. | 222 `iron-meta-query` can be used to access infomation stored in `iron-meta`. |
209 | 223 |
210 Examples: | 224 Examples: |
211 | 225 |
212 If I create an instance like this: | 226 If I create an instance like this: |
213 | 227 |
214 <iron-meta key="info" value="foo/bar"></iron-meta> | 228 <iron-meta key="info" value="foo/bar"></iron-meta> |
215 | 229 |
216 Note that value="foo/bar" is the metadata I've defined. I could define more | 230 Note that value="foo/bar" is the metadata I've defined. I could define more |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 list: { | 277 list: { |
264 type: Array, | 278 type: Array, |
265 notify: true | 279 notify: true |
266 } | 280 } |
267 | 281 |
268 }, | 282 }, |
269 | 283 |
270 /** | 284 /** |
271 * Actually a factory method, not a true constructor. Only runs if | 285 * Actually a factory method, not a true constructor. Only runs if |
272 * someone invokes it directly (via `new Polymer.IronMeta()`); | 286 * someone invokes it directly (via `new Polymer.IronMeta()`); |
| 287 * |
| 288 * @param {{type: (string|undefined), key: (string|undefined)}=} config |
273 */ | 289 */ |
274 factoryImpl: function(config) { | 290 factoryImpl: function(config) { |
275 if (config) { | 291 if (config) { |
276 for (var n in config) { | 292 for (var n in config) { |
277 switch(n) { | 293 switch(n) { |
278 case 'type': | 294 case 'type': |
279 case 'key': | 295 case 'key': |
280 this[n] = config[n]; | 296 this[n] = config[n]; |
281 break; | 297 break; |
282 } | 298 } |
(...skipping 25 matching lines...) Expand all Loading... |
308 * @return {*} | 324 * @return {*} |
309 */ | 325 */ |
310 byKey: function(key) { | 326 byKey: function(key) { |
311 return this._metaData && this._metaData[key]; | 327 return this._metaData && this._metaData[key]; |
312 } | 328 } |
313 | 329 |
314 }); | 330 }); |
315 | 331 |
316 })(); | 332 })(); |
317 </script> | 333 </script> |
OLD | NEW |