aboutsummaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2018-01-21 10:36:32 +0100
committerThomas Lange <code@nerdmind.de>2018-01-21 10:36:32 +0100
commit7d9b548391780db5d590a7148411b6eb59c189fb (patch)
tree9269331b5ab34681483a1d3deaf2c7c827644315 /static
parent1a896a9bc176e1af35ee47ebe37cb59d613d2a4f (diff)
downloadbigpipe-7d9b548391780db5d590a7148411b6eb59c189fb.tar.gz
bigpipe-7d9b548391780db5d590a7148411b6eb59c189fb.tar.xz
bigpipe-7d9b548391780db5d590a7148411b6eb59c189fb.zip
Change the mechanism how BigPipe detects the last pagelet
This commit is a preparation for a few further commits and changes the mechanism how the BigPipe javascript library detects the last flushed pagelet from server. Previously, there was a "IS_LAST:true" property in the JSON encoded pagelet object. However, this meant that when the pagelet was sent to the client, the server already needed to know at this point that this is the last pagelet. This can no longer be reliably determined in the future due to smaller restructuring. Instead of sending "IS_LAST:true" within the JSON encoded pagelet object of the last pagelet, the BigPipe::render() method on the server will display a <script> element which calls "BigPipe.onLastPageletArrived()" after all pagelets have been flushed. This call informs the javascript library that the last pagelet has been flushed and arrived at the client. This is required because the BigPipe javascript library otherwise doesn't know that the last pagelet has been arrived (the javascript library waits for all pagelets to be flushed and displayed until it begins to execute the external javascript resources of every pagelet).
Diffstat (limited to 'static')
-rw-r--r--static/bigpipe.js27
1 files changed, 18 insertions, 9 deletions
diff --git a/static/bigpipe.js b/static/bigpipe.js
index ae15935..86d1cbe 100644
--- a/static/bigpipe.js
+++ b/static/bigpipe.js
@@ -270,6 +270,7 @@ BigPipe = (function() {
phase: 0,
done: [],
wait: [],
+ interval: null,
onPageletArrive(data, codeContainer) {
let pageletHTML = codeContainer.innerHTML;
@@ -284,10 +285,6 @@ BigPipe = (function() {
this.phase = 1;
}
- if(data.IS_LAST) {
- this.phase = 2;
- }
-
if(pagelet.NEED.length === 0 || pagelet.NEED.every(function(needID) {
return BigPipe.done.indexOf(needID) !== -1;
})) {
@@ -299,6 +296,17 @@ BigPipe = (function() {
}
},
+ onLastPageletArrived() {
+ this.phase = 2;
+
+ this.interval = setInterval(() => {
+ if(this.done.length === this.pagelets.length) {
+ clearInterval(this.interval);
+ this.executeJavascriptResources();
+ }
+ }, 50);
+ },
+
onPageletHTMLreplaced(pageletID) {
BigPipe.done.push(pageletID);
@@ -314,11 +322,6 @@ BigPipe = (function() {
pagelet.execute();
}
}
-
- // Check if this was the last pagelet and then execute loading of the external JS resources
- if(BigPipe.phase === 2 && BigPipe.done.length === BigPipe.pagelets.length) {
- BigPipe.executeJavascriptResources();
- }
},
executeJavascriptResources() {
@@ -340,6 +343,10 @@ BigPipe = (function() {
BigPipe.onPageletArrive(data, codeContainer);
},
+ onLastPageletArrived() {
+ BigPipe.onLastPageletArrived();
+ },
+
reset() {
BigPipe.pagelets.forEach(function(pagelet) {
pagelet.resources[Resource.TYPE_STYLESHEET].forEach(function(resource) {
@@ -357,6 +364,8 @@ BigPipe = (function() {
document.execCommand('Stop');
}
+ clearInterval(BigPipe.interval);
+
BigPipe.pagelets = [];
BigPipe.phase = 0;
BigPipe.wait = [];