Skip to content

Commit

Permalink
Simplify custom-style property deferment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 13, 2015
1 parent 115594d commit a970493
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/lib/custom-style.html
Expand Up @@ -145,8 +145,18 @@
// Allow all custom-styles defined in this turn to register
// before applying any properties. This helps ensure that all properties
// are defined before any are consumed.
Polymer.RenderStatus.beforeNextRender(this,
this._applyCustomProperties, [e]);
// Premature application of properties can occur in 2 cases:
// (1) A property is consumed in a style created before it is produced.
// In general, we require custom properties to be defined before usage
// for elements so this case is only to be slightly more like native
// custom properties where this construction is supported.
// (2) A set of in order styles (A, B) are re-ordered due to a parser
// yield A wait for textContent, making B go before A. This case
// can occur with native or polyflled webcomponents.
var self = this;
requestAnimationFrame(function() {
self._applyCustomProperties(e);
});
}
},

Expand Down
11 changes: 1 addition & 10 deletions src/lib/render-status.html
Expand Up @@ -50,20 +50,13 @@
},

_afterNextRenderQueue: [],
_beforeNextRenderQueue: [],

_waitingNextRender: false,

afterNextRender: function(element, fn, args) {
this._watchNextRender();
this._afterNextRenderQueue.push([element, fn, args]);
},

beforeNextRender: function(element, fn, args) {
this._watchNextRender();
this._beforeNextRenderQueue.push([element, fn, args]);
},

_watchNextRender: function() {
if (!this._waitingNextRender) {
this._waitingNextRender = true;
Expand All @@ -79,14 +72,12 @@
},

_flushNextRender: function() {
this._waitingNextRender = false;
this._flushRenderCallbacks(this._beforeNextRenderQueue);
this._beforeNextRenderQueue = [];
var self = this;
// we want to defer after render until just after the paint.
setTimeout(function() {
self._flushRenderCallbacks(self._afterNextRenderQueue);
self._afterNextRenderQueue = [];
self._waitingNextRender = false;
});
},

Expand Down

0 comments on commit a970493

Please sign in to comment.