Suggestion: Ability to use arrays of child-nodes everywhere a single node can be used.
See original GitHub issueOne 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:
- Created 8 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Many utility libraries, both Ramda and Lodash, have a
flatten
function. I.e. one can just doh('div', flatten([...]))
. This seems like a reasonable solution to me so I’ll close this. Feel free to reopen if you disagree 😄@kay999
vnode
is now part of the documentation.