infernojs / inferno

:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
https://infernojs.org
MIT License
16.09k stars 634 forks source link

CreateTemplate not returning value. #115

Closed Cmdv closed 8 years ago

Cmdv commented 8 years ago

Hi,

We're trying to test out Inferno as a virtual DOM for CycleJS but are hitting a pain point with our current tests.

This is the test in question, ignoring the technicalities of Cycle under the hood we pass html: through a function called toHTML.

describe('HTML Driver', function () {
  it('should output HTML when given a simple vtree stream', function (done) {
    function app() {
      return {
        html: Rx.Observable.just(div('.test-element', ['Foobar']))
      };
    }
    let {sinks, sources} = Cycle.run(app, {
      html: makeHTMLDriver()
    });
    sources.html.subscribe(html => {
      assert.strictEqual(html, '<div class="test-element">Foobar</div>');
      done();
    });
  });
});

div('.test-element', ['Foobar']) get converted to example below

// this is the vTree
{ tag: 'DIV',
  attrs: { className: 'test-element' },
  children: [ 'Foobar' ] }

toHTML is the function which receives our converted vTree

function toHTML(vTree) {
  const shape = isTemplate(vTree) ?
    vTree :
    createTemplate(() => vTree)(`cycle-inferno`)
  return renderToString(shape)
}

createTemplate(() => vTree)('cycle-inferno') returns nothing not even null and our tests err log is:

Uncaught ReferenceError: document is not defined

The code in question is located here. @TylorS has been able to implement Snabbdom to be used with Cycle here

Wonder if using Inferno in this manner would be possible? or from reading your tests on CreateTemplate the use of render was in an afterEach is that a requirement, or are we using it totally wrong?

Thanks :smile:

trueadm commented 8 years ago

Hey @Cmdv, I'd hold about for a few days. Currently, we're in the process of changing how Inferno works behind the scene. We're reducing the size of its core massively, improving performance and going to a stricter vdom structure by leveraging some other performance insights. I'll be happy to discuss this more on Gitter/Slack. :)

trueadm commented 8 years ago

closing this as the spike branch no longer has this issue and will soon be merged to master.