-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor SSR flow to support await data prepare
- Loading branch information
Showing
5 changed files
with
182 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
"use strict"; | ||
|
||
const xaa = require("xaa"); | ||
/* | ||
* subapp start for SSR | ||
* Nothing needs to be done to start subapp for SSR | ||
*/ | ||
module.exports = function setup() { | ||
return { | ||
process: () => { | ||
return "\n<!-- subapp start -->\n"; | ||
process: (context, token) => { | ||
const { xarcSubappSSR } = context.user; | ||
const startMsg = "\n<!-- subapp start -->\n"; | ||
|
||
if (!xarcSubappSSR) return startMsg; | ||
|
||
const concurrency = token.props.concurrency > 0 ? token.props.concurrency : 15; | ||
xaa.map( | ||
Object.entries(xarcSubappSSR), | ||
async ([, { queue }]) => { | ||
await xaa.map( | ||
queue, | ||
async info => { | ||
// make sure subapp is ready with SSR | ||
if (info.ready) await info.ready.promise; | ||
// and then wait for it to complete data prepare | ||
// awaitData should be available once ready is awaited | ||
await info.awaitData; | ||
}, | ||
{ concurrency } | ||
); | ||
|
||
// finally kick off rendering for every subapp in the group | ||
await xaa.map( | ||
queue, | ||
async ({ renderSSR }) => { | ||
if (renderSSR) await renderSSR(); | ||
}, | ||
{ concurrency } | ||
); | ||
}, | ||
{ concurrency } | ||
); | ||
|
||
return startMsg; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters