diff options
author | Thomas Lange <code@nerdmind.de> | 2018-01-21 10:36:32 +0100 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2018-01-21 10:36:32 +0100 |
commit | 7d9b548391780db5d590a7148411b6eb59c189fb (patch) | |
tree | 9269331b5ab34681483a1d3deaf2c7c827644315 /include | |
parent | 1a896a9bc176e1af35ee47ebe37cb59d613d2a4f (diff) | |
download | bigpipe-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 'include')
-rw-r--r-- | include/classes/BigPipe/BigPipe.php | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php index c5f33e3..6e4c7f4 100644 --- a/include/classes/BigPipe/BigPipe.php +++ b/include/classes/BigPipe/BigPipe.php @@ -42,13 +42,9 @@ class BigPipe { #=============================================================================== # Prints a single pagelet response #=============================================================================== - private static function singleResponse(Pagelet $Pagelet, $last = FALSE) { + private static function singleResponse(Pagelet $Pagelet) { $pageletJSON = $Pagelet->getStructure(); - if($last) { - $pageletJSON['IS_LAST'] = TRUE; - } - $pageletHTML = removeLineBreaksAndTabs($Pagelet->getHTML()); $pageletHTML = str_replace('--', '--', $pageletHTML); @@ -100,11 +96,15 @@ class BigPipe { } else { - self::singleResponse($Pagelet, (count(self::$pagelets) === ++$i)); + self::singleResponse($Pagelet); self::flushOutputBuffer(); } } } + + if(BigPipe::enabled()) { + echo "<script>BigPipe.onLastPageletArrived();</script>\n"; + } } } ?>
\ No newline at end of file |