OLD | NEW |
| (Empty) |
1 | |
2 | |
3 // until ES6 modules become standard, we follow Occam and simply stake out | |
4 // a global namespace | |
5 | |
6 // Polymer is a Function, but of course this is also an Object, so we | |
7 // hang various other objects off of Polymer.* | |
8 (function() { | |
9 var userPolymer = window.Polymer; | |
10 | |
11 window.Polymer = function(prototype) { | |
12 var ctor = desugar(prototype); | |
13 // native Custom Elements treats 'undefined' extends property | |
14 // as valued, the property must not exist to be ignored | |
15 var options = { | |
16 prototype: ctor.prototype | |
17 }; | |
18 if (prototype.extends) { | |
19 options.extends = prototype.extends; | |
20 } | |
21 Polymer.telemetry._registrate(prototype); | |
22 document.registerElement(prototype.is, options); | |
23 return ctor; | |
24 }; | |
25 | |
26 var desugar = function(prototype) { | |
27 prototype = Polymer.Base.chainObject(prototype, Polymer.Base); | |
28 prototype.registerCallback(); | |
29 return prototype.constructor; | |
30 }; | |
31 | |
32 window.Polymer = Polymer; | |
33 | |
34 if (userPolymer) { | |
35 for (var i in userPolymer) { | |
36 Polymer[i] = userPolymer[i]; | |
37 } | |
38 } | |
39 | |
40 Polymer.Class = desugar; | |
41 | |
42 })(); | |
43 /* | |
44 // Raw usage | |
45 [ctor =] Polymer.Class(prototype); | |
46 document.registerElement(name, ctor); | |
47 | |
48 // Simplified usage | |
49 [ctor = ] Polymer(prototype); | |
50 */ | |
51 | |
52 // telemetry: statistics, logging, and debug | |
53 | |
54 Polymer.telemetry = { | |
55 registrations: [], | |
56 _regLog: function(prototype) { | |
57 console.log('[' + prototype.is + ']: registered') | |
58 }, | |
59 _registrate: function(prototype) { | |
60 this.registrations.push(prototype); | |
61 Polymer.log && this._regLog(prototype); | |
62 }, | |
63 dumpRegistrations: function() { | |
64 this.registrations.forEach(this._regLog); | |
65 } | |
66 }; | |
67 | |
OLD | NEW |