diff options
author | Thomas Lange <code@nerdmind.de> | 2018-12-31 00:23:06 +0100 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2018-12-31 00:23:06 +0100 |
commit | a0725d0bf159283e278168e3bd1dc0fe3e6da7ab (patch) | |
tree | a7788e618b82c7957cc56e2be3967fcfa8f03df0 /static | |
parent | df4865e7bcc3857be2f4b57d565a501a097b0daa (diff) | |
download | bigpipe-last-pagelet-event-optimization.tar.gz bigpipe-last-pagelet-event-optimization.tar.xz bigpipe-last-pagelet-event-optimization.zip |
Temporary branch: last-pagelet-event-optimizationlast-pagelet-event-optimization
Diffstat (limited to 'static')
-rw-r--r-- | static/bigpipe.js | 36 |
1 files changed, 28 insertions, 8 deletions
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() { |