From a0725d0bf159283e278168e3bd1dc0fe3e6da7ab Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 31 Dec 2018 00:23:06 +0100 Subject: Temporary branch: last-pagelet-event-optimization --- static/bigpipe.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'static') diff --git a/static/bigpipe.js b/static/bigpipe.js index cc048a5..41bd4fd 100644 --- a/static/bigpipe.js +++ b/static/bigpipe.js @@ -272,7 +272,27 @@ BigPipe = (function() { wait: [], interval: null, + eventNode: document, + eventName: "DOMContentLoaded", + eventFunc: function() { + BigPipe.onLastPageletArrived(); + BigPipe.unregisterEventListener(); + }, + + registerEventListener() { + this.eventNode.addEventListener(this.eventName, this.eventFunc, false); + }, + + unregisterEventListener() { + this.eventNode.removeEventListener(this.eventName, this.eventFunc, false); + }, + onPageletArrive(data, codeContainer) { + if(this.phase === 0) { + this.phase = 1; + this.registerEventListener(); + } + let pageletHTML = codeContainer.innerHTML; pageletHTML = pageletHTML.substring(5, pageletHTML.length - 4); codeContainer.parentNode.removeChild(codeContainer); @@ -281,10 +301,6 @@ BigPipe = (function() { this.pagelets.push(pagelet); - if(this.phase === 0) { - this.phase = 1; - } - if(pagelet.NEED.length === 0 || pagelet.NEED.every(function(needID) { return BigPipe.done.indexOf(needID) !== -1; })) { @@ -339,12 +355,16 @@ BigPipe = (function() { // Public-Access //============================================================================== return { - onPageletArrive(data, codeContainer) { - BigPipe.onPageletArrive(data, codeContainer); + setLastPageletEventNode(eventNode) { + BigPipe.eventNode = eventNode; }, - onLastPageletArrived() { - BigPipe.onLastPageletArrived(); + setLastPageletEventName(eventName) { + BigPipe.eventName = eventName; + }, + + onPageletArrive(data, codeContainer) { + BigPipe.onPageletArrive(data, codeContainer); }, reset() { -- cgit v1.2.3