Skip to content

Commit

Permalink
Simplify host stack, set __dataHost unconditionally, and make _regist…
Browse files Browse the repository at this point in the history
…erHost patchable.
  • Loading branch information
kevinpschaaf committed Sep 19, 2019
1 parent 50dbf55 commit 929d056
Showing 1 changed file with 17 additions and 40 deletions.
57 changes: 17 additions & 40 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ function setupBindings(inst, templateInfo) {
addNotifyListener(node, inst, binding);
}
}
// This ensures all bound elements have a host set, regardless
// of whether they upgrade synchronous to creation
node.__dataHost = inst;
}
}
Expand Down Expand Up @@ -1376,7 +1378,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
*/
_initializeProperties() {
super._initializeProperties();
hostStack.registerHost(this);
this._registerHost();
this.__dataClientsReady = false;
this.__dataPendingClients = null;
this.__dataToNotify = null;
Expand All @@ -1389,6 +1391,16 @@ export const PropertyEffects = dedupingMixin(superClass => {
this.__dataClientsInitialized = false;
}

_registerHost() {
if (hostStack.length) {
let host = hostStack[hostStack.length-1];
host._enqueueClient(this);
// This ensures even non-bound elements have a host set, as
// long as they upgrade synchronously
this.__dataHost = host;
}
}

/**
* Overrides `PropertyAccessors` implementation to provide a
* more efficient implementation of initializing properties from
Expand Down Expand Up @@ -2769,9 +2781,9 @@ export const PropertyEffects = dedupingMixin(superClass => {
templateInfo = templateInfo || /** @type {!TemplateInfo} */(this._bindTemplate(template, true));
// Ensures that created dom is `_enqueueClient`'d to this element so
// that it can be flushed on next call to `_flushProperties`
hostStack.beginHosting(this);
hostStack.push(this);
let dom = super._stampTemplate(template, templateInfo);
hostStack.endHosting(this);
hostStack.pop();
// Add template-instance-specific data to instanced templateInfo
templateInfo.nodeList = dom.nodeList;
// Capture child nodes to allow unstamping of non-prototypical templates
Expand Down Expand Up @@ -3164,7 +3176,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
});

/**
* Helper api for enqueuing client dom created by a host element.
* Stack for enqueuing client dom created by a host element.
*
* By default elements are flushed via `_flushProperties` when
* `connectedCallback` is called. Elements attach their client dom to
Expand All @@ -3186,39 +3198,4 @@ export const PropertyEffects = dedupingMixin(superClass => {
*
* @private
*/
class HostStack {
constructor() {
this.stack = [];
}

/**
* @param {*} inst Instance to add to hostStack
* @return {void}
*/
registerHost(inst) {
if (this.stack.length) {
let host = this.stack[this.stack.length-1];
host._enqueueClient(inst);
}
}

/**
* @param {*} inst Instance to begin hosting
* @return {void}
*/
beginHosting(inst) {
this.stack.push(inst);
}

/**
* @param {*} inst Instance to end hosting
* @return {void}
*/
endHosting(inst) {
let stackLen = this.stack.length;
if (stackLen && this.stack[stackLen-1] == inst) {
this.stack.pop();
}
}
}
const hostStack = new HostStack();
const hostStack = [];

0 comments on commit 929d056

Please sign in to comment.