How to use inferno-server - 10 common examples

To help you get started, we’ve selected a few inferno-server 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 infernojs / inferno-website / src / server / middleware / render.js View on Github external
export default async(ctx, next) => {

  const context = {};
  const content = renderToString(
    
      
        {routes}
      
    
  );

  // This will contain the URL to redirect to if  was used
  if (context.url) {
    return ctx.redirect(context.url);
  }

  ctx.type = 'text/html';
  ctx.body = '\n' + content;
  await next();
};
github joe-sky / nornj / test / htmlTemplateUseInfernoSpec.js View on Github external
var data = {
            name: 'joe_sky',
            id: 100,
            test0: true,
            list: [{ no: 1, b: 1 }, { no: 2, b: 0 }, { no: 3, b: 1 }],
            styles: { color: 'blue', fontSize: '15px' },
            //testcom: TestComponent
          };

          //nj.registerComponent('TestComponent', TestComponent);

          var templateT = nj.compileTagComponent(window.document.querySelector('div'), 'testT1');
          //console.log(JSON.stringify(nj.templates['testT1']));
          //console.log(templateT(data));

          var html = InfernoServer.renderToString(templateT(data));

          console.log(html);
          expect(html).toBeTruthy();
          done();
        }
      );
github infernojs / inferno / packages / inferno-server / __tests__ / observer.spec.server.jsx View on Github external
it('does not views alive when using static + string rendering', function() {
    useStaticRendering(true);

    let renderCount = 0;
    const data = mobx.observable({
      z: 'hi'
    });

    const TestComponent = observer(function testComponent() {
      renderCount++;
      return <div>{data.z}</div>;
    });

    const output = renderToStaticMarkup();

    data.z = 'hello';

    expect(output).toBe('<div>hi</div>');
    expect(renderCount).toBe(1);

    expect(getDNode(data, 'z').observers.length).toBe(0);

    useStaticRendering(false);
  });
});
github infernojs / inferno / packages / inferno-server / __tests__ / creation.spec.server.js View on Github external
it(test.description, () => {
      const container = document.createElement('div');
      const vDom = test.template('foo');
      const output = renderToStaticMarkup(vDom);

      document.body.appendChild(container);
      container.innerHTML = output;
      expect(output).toBe(test.result);
      document.body.removeChild(container);
    });
  });
github infernojs / inferno / packages / inferno-server / __tests__ / props-context.spec.server.jsx View on Github external
it('stateless has context as 2nd argument', () =&gt; {
    function TestChild(props, context) {
      return <p>{context.testContext}</p>;
    }

    const output = renderToStaticMarkup(
      
        
      
    );
    expect(output).toBe('<p>context-works</p>');
  });
github infernojs / inferno / packages / inferno-server / __tests__ / creation.spec.server.jsx View on Github external
it(test.description, () => {
      const container = document.createElement('div');
      const vDom = test.template('foo');
      const output = renderToStaticMarkup(vDom);

      document.body.appendChild(container);
      container.innerHTML = output;
      expect(output).toBe(test.result);
      document.body.removeChild(container);
    });
  });
github infernojs / inferno / packages / inferno-server / __tests__ / creation.spec.server.jsx View on Github external
}

        render() {
          return (
            <div>
              {this.state.foo}
              
            </div>
          );
        }
      }

      const container = document.createElement('div');
      const vDom = ;

      const output = renderToStaticMarkup(vDom);

      document.body.appendChild(container);
      container.innerHTML = output;
      expect(output).toBe('<div>bar2<div>bar2</div></div>');
      document.body.removeChild(container);
    });
  });
github infernojs / inferno / packages / inferno-server / __tests__ / creation-stream.spec.server.js View on Github external
return new Promise(function(res, rej) {
    streamAsStaticMarkup(dom)
      .on('error', rej)
      .pipe(
        concatStream(function(buffer) {
          res(buffer.toString('utf-8'));
        })
      );
  });
}
github infernojs / inferno / packages / inferno-server / __tests__ / creation-stream.spec.server.jsx View on Github external
return new Promise(function(res, rej) {
    streamAsString(dom)
      .on('error', rej)
      .pipe(
        concatStream(function(buffer) {
          res(buffer.toString('utf-8'));
        })
      );
  });
}
github infernojs / inferno / packages / inferno-server / __tests__ / creation-queuestream.spec.server.jsx View on Github external
return new Promise(function(res, rej) {
    const chunks = [];
    streamQueueAsString(dom)
      .on('error', rej)
      .on('data', chunk => {
        chunks.push(chunk.toString());
      })
      .pipe(
        concatStream(function(buffer) {
          res([chunks, buffer.toString('utf-8')]);
        })
      );
  });
}

inferno-server

Provides methods to render HTML strings from Inferno elements

MIT
Latest version published 1 year ago

Package Health Score

71 / 100
Full package analysis