export function PREBOOT_FACTORY()

in src/lib/provider.ts [39:91]


export function PREBOOT_FACTORY(doc: Document,
                                prebootOpts: PrebootOptions,
                                nonce: string|null,
                                platformId: Object,
                                appRef: ApplicationRef,
                                eventReplayer: EventReplayer) {
  return () => {
    validateOptions(prebootOpts);

    if (isPlatformServer(platformId)) {
      const inlineCodeDefinition = getInlineDefinition(prebootOpts);
      const scriptWithDefinition = createScriptFromCode(doc, nonce, inlineCodeDefinition);
      const inlineCodeInvocation = getInlineInvocation();

      const existingScripts = doc.getElementsByClassName(PREBOOT_SCRIPT_CLASS);

      // Check to see if preboot scripts are already inlined before adding them
      // to the DOM. If they are, update the nonce to be current.
      if (existingScripts.length === 0) {
        const baseList: string[] = [];
        const appRootSelectors = baseList.concat(prebootOpts.appRoot);
        doc.head.appendChild(scriptWithDefinition);
        appRootSelectors
          .map(selector => ({
            selector,
            appRootElem: doc.querySelector(selector)
          }))
          .forEach(({selector, appRootElem}) => {
            if (!appRootElem) {
              console.log(`No server node found for selector: ${selector}`);
              return;
            }
            const scriptWithInvocation = createScriptFromCode(doc, nonce, inlineCodeInvocation);
            appRootElem.insertBefore(scriptWithInvocation, appRootElem.firstChild);
          });
      } else if (existingScripts.length > 0 && nonce) {
        (existingScripts[0] as any).nonce = nonce;
      }
    }
    if (isPlatformBrowser(platformId)) {
      const replay = prebootOpts.replay != null ? prebootOpts.replay : true;
      if (replay) {
        appRef.isStable
          .pipe(
            filter(stable => stable),
            take(1)
          ).subscribe(() => {
          eventReplayer.replayAll();
        });
      }
    }
  };
}