Allows you to use async/await syntax in ASP.NET Core NodeServices prerendering. Also includes some features.
npm install domain-wait

typescript
npm install domain-wait
`
* Add following lines to the SSR's entry point JS-file:
`javascript
// 1. Import library.
import { connect, getCompletedTasks } from "domain-wait";
//...
// 2. Find this function (it's a NodeServices entry point).
export default createServerRenderer((params) => {
//...
// 3. Find the promise.
return new Promise((resolve, reject) => {
//...
connect(params); // 4. Add in this line before (!) the first call of the render function.
renderApp(); // First call of the render application function.
//...
resolve({
//...
globals: {
//...
completedTasks: getCompletedTasks() // 5. Add this line to the each (!) 'globals' object.
//...
}
//...
});
});
})
`
* Add variable to the window object
Add the completedTasks array to the window object in Razor's .cshtml file:
`html
@Instead of using "aspnet-prerender" attribute / tag helper@
@inject Microsoft.AspNetCore.SpaServices.Prerendering.ISpaPrerenderer
@{
var prerenderResult = await prerenderer.RenderToString(%Path to JS file which will be entry point for the SSR%, customDataParameter: %Your data object from ASP.NET Core%);
var completedTasksJson = prerenderResult?.Globals?["completedTasks"]?.ToString();
}
@Instead of using "aspnet-prerender" attribute / tag helper@
@Html.Raw(prerenderResult?.Html)
`
Usage
* Import library
`typescript
import { wait, transformUrl } from "domain-wait";
`
* Tell to the NodeServices to wait for asynchronous function. Example with Axios:
`typescript
// NodeServices will be waiting for the request with Axios async method.
await wait(async (transformUrl) => {
var url = transformUrl("/api/Person");
var result = await Axios.get(url);
// ...
});
``