How to use the preboot.getInlineCode function in preboot

To help you get started, we’ve selected a few preboot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / universal / examples / next-hello-world / src / universal_modules / platform-node / node-platform.ts View on Github external
let components = appRef.components;
        let prebootCode;
        // TODO(gdi2290): hide cache in (ngPreboot|UniversalPreboot)
        let key = (typeof _config.preboot === 'object') && JSON.stringify(_config.preboot) || null;
        let prebootEl;
        let el;
        let lastRef;
        try {
          if (key && NodePlatform._cache.has(key)) {
            prebootEl = NodePlatform._cache.get(key).prebootEl;
            // prebootCode = NodePlatform._cache.get(key);
          } else if (key && !prebootEl) {
            config.time && console.time('preboot insert: ' + config.id);
            prebootCode = parseFragment(''+
              '' +
            '');
            prebootEl = DOM.createElement('div');

            for (let i = 0; i < prebootCode.childNodes.length; i++) {
              DOM.appendChild(prebootEl, prebootCode.childNodes[i]);
            }
            NodePlatform._cache.set(key, {prebootCode, prebootEl});
            config.time && console.timeEnd('preboot insert: ' + config.id);
          }
          //  else {
          //   prebootCode = getInlineCode(_config.preboot);
          // }
          // assume last component is the last component selector
          // TODO(gdi2290): provide a better way to determine last component position
          lastRef = components[components.length - 1];
github angular / universal / modules / platform-node / node-platform.ts View on Github external
let components = appRef.components;
        let prebootCode = null;
        // TODO(gdi2290): hide cache in (ngPreboot|UniversalPreboot)
        let key = (typeof UNIVERSAL_CONFIG.preboot === 'object') && JSON.stringify(UNIVERSAL_CONFIG.preboot) || null;
        let prebootEl = null;
        let el = null;
        let lastRef = null;
        try {
          if (key && NodePlatform._cache.has(key)) {
            prebootEl = NodePlatform._cache.get(key).prebootEl;
            // prebootCode = NodePlatform._cache.get(key);
          } else if (key && !prebootEl) {
            config.time && console.time('id: ' + config.id + ' preboot insert: ');
            prebootCode = parseFragment('' +
              '' +
            '');
            prebootEl = DOM.createElement('div');
            DOM.appendChild(prebootEl, prebootCode.childNodes[0]);
            NodePlatform._cache.set(key, {prebootCode, prebootEl});
            config.time && console.timeEnd('id: ' + config.id + ' preboot insert: ');
          }
          //  else {
          //   prebootCode = getInlineCode(_config.preboot);
          // }
          // assume last component is the last component selector
          // TODO(gdi2290): provide a better way to determine last component position
          lastRef = components[components.length - 1];
          el = lastRef.location.nativeElement;
          DOM.insertAfter(el, prebootEl);
          // let script = parseFragment(prebootCode);
github aurelia / ssr-engine / src / transformers / preboot.ts View on Github external
appRoot: options.appRoots || ['body'],
        eventSelectors: [
            // for recording changes in form elements
            { selector: 'input,textarea', events: ['keypress', 'keyup', 'keydown', 'input', 'change'] },
            { selector: 'select,option', events: ['change'] },
            // when user hits return button in an input box
            { selector: 'input', events: ['keyup'], preventDefault: true, keyCodes: [13], freeze: true },
            // for tracking focus (no need to replay)
            { selector: 'input,textarea', events: ['focusin', 'focusout', 'mousedown', 'mouseup'], noReplay: true },
            { selector: 'button[type="submit"]', events: ['submit'], preventDefault: false, freeze: true },
            { selector: 'form', events: ['submit'], preventDefault: true, freeze: true },
            // user clicks on a button
            { selector: 'button:not([type="submit"])', events: ['click'], preventDefault: true, freeze: true }
        ]
      }, options.prebootOptions);
      const inlinePrebootCode = preboot.getInlineCode(prebootOptions);
      html = appendToHead(html, `\r\n\r\n`);

      // preboot_browser can replay events that were stored by the preboot code
      html = appendToBody(html, `\r\n
      `);
  }

  return html;
};
github ng-consult / ng1-server / src / bridge_S2.ts View on Github external
socket.on(MSG.IDLE, (response: PARAM_IDLE) => {

                debug('received IDLE from EEE', response.uid, response.url, response.html.length);

                debug('responseCache = ', response.exportedCache);

                const serialized = JSON.stringify(response.exportedCache);
                const script = ``;
                let superHTML: string = response.html.replace(/<\/head>/, script);


                if(this.preboot) {
                    const prebootOptions = {
                        appRoot: 'document.body'
                    };
                    const inlinePrebootCode = '';
                    superHTML = superHTML.replace(/<\/body>/, inlinePrebootCode);
                }

                if( Bridge_Pool.pool[response.uid].query.strategy === ENUM_CACHE_STATUS.RENDER_CACHE) {
                    const newUrl = new UrlCache(Bridge_Pool.pool[response.uid].query.url);
                    newUrl.set(superHTML, {}, (err, status) => {
                        if(err) {
                            ServerLog.Log.child({uid: response.uid, script: 'Bridge_S2'}).error({response: response, err: err});
                            throw err;
                        }
                        debug('Cache on Bridge_MSG_2.CACHE_IT status = ', status);
                    });
                }
                Bridge_Pool.sendHTML_to_Client(response.uid, superHTML);
                socket.emit(MSG.IDLE + response.uid);
            });