Hyperapp: Lazy components cannot return arrays

Created on 24 May 2018  路  16Comments  路  Source: jorgebucaran/hyperapp

var h = hyperapp.h, app = hyperapp.app;
/*@jsx h*/
var SomeComponent = function () {
    return function () {
        return [<p>Hello</p>];
    };
};

app({}, {}, function () {
    return (<div oncreate={function (e) {
        setTimeout(function () { alert(e.innerHTML); }, 0); // <undefined></undefined> would be alerted.
    }}>
        <SomeComponent/>
    </div>);
}, document.getElementById("app"));

See JSFiddle: https://jsfiddle.net/vmvaywrr/2/

Bug

All 16 comments

Lazy components being an immensely helpful thing in Hyperapp 1.x, I wish that this could some day be fixed.

Correct. By the way, lazy components will be removed in 2.0.

But I suggest that 1.x users be respected.

I won't publish a 1.x without lazy components, no worries. 馃檹

The problem that top-level components cannot be arrays could theoretically, in my opinion, be solved with the same fix as stated here.
See also #362 #687

@infinnie It would still not solve the problem of returning null from lazy components. Currently, we just turn null and undefined to "" for lazy components, but that's a poor hack and one of the reasons I want to remove lazy components. It's too troublesome to diff null nodes after the old and new node lists are computed.

EDIT: By the way, I am not saying there's no solution, certainly there is more than one way to do this, we can imagine, but it has never been my intention to add every possible feature (solve every single problem with) to Hyperapp as that would trade elegance, simplicity, a small code base, and other subjective points that I highly value about Hyperapp.

For arrays, yeah, sorry I mixed two different things: null returning subviews and array returning components or subviews.

After 2.0, and after I've sorted other priorities I'll experiment again with diffing arrays/fragments using the DocumentFragment API.

So, I am going to close in favor of https://github.com/hyperapp/hyperapp/issues/530

684 now pretty solves this bug if merged.

(and it actually only takes 3 lines to fix it.)

@infinnie Can you link me to the diff, please?

Array.isArray() is ES5, supported by IE9

However my fix poses another constraint that the top-level view cannot return null but has to return an empty string in order to not render anything: https://github.com/infinnie/hyperapp/commit/d07f2e152b29b901575bbd53ce28cab4dfbc43f7

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zaceno picture zaceno  路  3Comments

zhaotoday picture zhaotoday  路  3Comments

jorgebucaran picture jorgebucaran  路  3Comments

Mytrill picture Mytrill  路  4Comments

jbrodriguez picture jbrodriguez  路  4Comments