Skip to content

Commit

Permalink
native createdCallback fires immediately on element creation, befor…
Browse files Browse the repository at this point in the history
…e children are processed, so <script> tag embedded in <polymer-element> is not executed when the latter is upgraded:

modify the instantiation process so that embedded definitions still work (now a `noscript` attribute is required for elements with no script portion);
factor lifecycle methods to support both `createdCallback' and `readyCallback` as we transition to the former
  • Loading branch information
Scott J. Miles committed Jul 17, 2013
1 parent 448c4d7 commit 9a0879f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/declaration/polymer-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
var extend = Polymer.extend;
var apis = scope.api.declaration;

var deferred = {};

// imperative implementation: Polymer()

// maps tag names to prototypes
Expand All @@ -18,6 +20,9 @@
// register an 'own' prototype for tag `name`
function element(name, prototype) {
registry[name] = prototype;
if (deferred[name]) {
deferred[name].define();
}
}

// returns a prototype that chains to <tag> or HTMLElement
Expand All @@ -29,8 +34,24 @@

var prototype = generatePrototype();
extend(prototype, {
// custom element processing
// TODO(sjmiles): temporary BC
readyCallback: function() {
this._createdCallback();
},
createdCallback: function() {
this._createdCallback();
},
// custom element processing
_createdCallback: function() {
// fetch our element name
var name = this.getAttribute('name');
if (registry[name] || this.hasAttribute('noscript')) {
this.define();
} else {
deferred[name] = this;
}
},
define: function() {
// fetch our element name
var name = this.getAttribute('name');
// fetch our extendee name
Expand Down
11 changes: 9 additions & 2 deletions src/instance/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
// user entry point for constructor-like initialization
ready: function() {
},
// system entry point, do not override
// TODO(sjmiles): temporary BC
readyCallback: function() {
this._createdCallback();
},
createdCallback: function() {
this._createdCallback();
},
// system entry point, do not override
_createdCallback: function() {
//this.style.display = 'inline-block';
// install property observers
// do this first so we can observe changes during initialization
Expand All @@ -31,7 +38,7 @@
// bindings will self destruct after a short time; this is
// necessary to make elements collectable as garbage
// when polyfilling Object.observe
this.asyncUnbindAll();
//this.asyncUnbindAll();
// user initialization
this.ready();
},
Expand Down

0 comments on commit 9a0879f

Please sign in to comment.