question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: Ability to use arrays of child-nodes everywhere a single node can be used.

See original GitHub issue

One suggestion: It would be helpful if vnodes could insert arrays of vnodes instead of only a single one. This would make it much more flexible and would eliminate the need for “useless” in-between container-tags (which genrally works fine, but is problematic for certain use-cases for example when using a nth-child-selector in css).

To circumvent this, in the moment I use a simple ‘h’-wrapper which flattens it’s arguments before inserting:

function flatten(data) {
    var res = [];
    function flat(data) {
        _.each(data, function(v) {
            if (v === null || v === undefined || v === false) {}
            else if (_.isArray(v)) flat(v);
            else res.push(v);
        })
    }
    flat(data);
    return res;
}
exports.h = function(tag, opts, args) {
    return h(tag, opts || {}, flatten(Array.prototype.slice.call(arguments, 2)))
};

This makes building node-trees much easier (but requires a {} if there are any child nodes).

Problem with my solution: It won’t work for thunks, because data.vnode only supports a child-node. So if there is a new thunk-implementation comming, maybe it’s possible to address this problem, too.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
paldepindcommented, Oct 12, 2016

Many utility libraries, both Ramda and Lodash, have a flatten function. I.e. one can just do h('div', flatten([...])). This seems like a reasonable solution to me so I’ll close this. Feel free to reopen if you disagree 😄

0reactions
TylorScommented, Apr 12, 2016

@kay999 vnode is now part of the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java_functions_algorithms Flashcards - Quizlet
-split array into 2 parts: one with elements larger than the pivot; ... every node has 2 child nodes except the leaf nodes....
Read more >
XML and MATLAB: Navigating a Tree
In the above example I used getFirstChild() which returns the first child (in this case, the Name node). Then using the getNextSibling() method, ......
Read more >
Trees in Data Structure: Types, Properties and Applications
A binary tree is a special type of tree where each and every node can have no more than two child nodes. The...
Read more >
Basics - TreeList - Kendo UI for Angular - Telerik
fetchChildren -а function used to retrieve the child nodes of a particular node. Returns an array or an observable. The following example demonstrates...
Read more >
Strange behaviour of splice method in the context of childnodes
Node.childnodes returns a Node List which is not an array in JavaScript. So you cannot apply splice to it. As MDN notes, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found