virtual-element
Advanced tools
Comparing version 1.1.2 to 1.2.0
13
index.js
@@ -46,3 +46,3 @@ /** | ||
if (arguments.length === 2 && (typeof attributes === 'string' || Array.isArray(attributes))) { | ||
children = attributes | ||
children = [ attributes ] | ||
attributes = {} | ||
@@ -53,3 +53,3 @@ } | ||
// This is essentially just the ES6 rest param | ||
if (arguments.length > 2 && children && Array.isArray(arguments[2]) === false) { | ||
if (arguments.length > 2) { | ||
children = slice(arguments, 2) | ||
@@ -61,11 +61,8 @@ } | ||
// passing in a single child, you can skip | ||
// using the array | ||
if (!Array.isArray(children)) { | ||
children = [children] | ||
} | ||
// Flatten nested child arrays. This is how JSX compiles some nodes. | ||
children = flatten(children, 2) | ||
// Filter out any `undefined` elements | ||
children = children.filter(function (i) { return typeof i !== 'undefined' }) | ||
// if you pass in a function, it's a `Component` constructor. | ||
@@ -72,0 +69,0 @@ // otherwise it's an element. |
{ | ||
"name": "virtual-element", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"repository": "dekujs/virtual-element", | ||
@@ -5,0 +5,0 @@ "description": "Build virtual tree elements", |
@@ -77,2 +77,23 @@ /** | ||
it('should allow sparse lists of children', function () { | ||
var node | ||
node = element('div', {}, null, 'a', 'b', null, 'c') | ||
assert(node.children.length, 5) | ||
// even w/o attrs | ||
node = element('div', 'a', null, 'c') | ||
assert(node.children.length, 3) | ||
}) | ||
it('should allow nested arrays as children', function () { | ||
var node | ||
node = element('div', {}, null, [ 'a', 'b' ], 'c') | ||
assert(node.children.length, 3) | ||
node = element('div', null, [ 'a', 'b' ], 'c') | ||
assert(node.children.length, 3) | ||
}) | ||
it('should not treat undefined as a child', function () { | ||
@@ -94,2 +115,9 @@ var node | ||
it('should not ignore subsequent children when the first is undefined', function () { | ||
var node | ||
node = element('div', {}, undefined, 'a') | ||
assert.strictEqual(node.children.length, 1) | ||
}) | ||
it('render nodes that work with JSX', function(){ | ||
@@ -96,0 +124,0 @@ assert.deepEqual( |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5963
6
163
1