Comparing version 2.4.0 to 2.5.0
var React = require('react') | ||
var toString = require('react-dom/server').renderToString | ||
var hyperx = require('../') | ||
var hx = hyperx(React.createElement) | ||
// hyperx always uses a children array, but react needs children as separate arguments, | ||
// so spread them using this wrapper | ||
function createElement (tag, props, children) { | ||
return React.createElement.apply(null, [tag, props].concat(children)) | ||
} | ||
function createFragment (children) { | ||
return createElement(React.Fragment, {}, children) | ||
} | ||
var hx = hyperx(createElement, { | ||
createFragment: createFragment | ||
}) | ||
var title = 'world' | ||
var wow = [1,2,3] | ||
var frag = hx` | ||
<tr> <td>row1</td> </tr> | ||
<tr> <td>row2</td> </tr> | ||
` | ||
var tree = hx`<div> | ||
@@ -13,5 +30,7 @@ <h1 y="ab${1+2}cd">hello ${title}!</h1> | ||
${wow.map(function (w, i) { | ||
return hx`<b>${w}</b>\n` | ||
return hx`<b key="${i}">${w}</b>\n` | ||
})} | ||
<table>${frag}</table> | ||
</div>` | ||
console.log(toString(tree)) |
@@ -140,2 +140,3 @@ var attrToProp = require('hyperscript-attribute-to-property') | ||
|| (tree[2].length === 2 && /\S/.test(tree[2][1]))) { | ||
if (opts.createFragment) return opts.createFragment(tree[2]) | ||
throw new Error( | ||
@@ -276,5 +277,2 @@ 'multiple root elements must be wrapped in an enclosing tag' | ||
var hasOwn = Object.prototype.hasOwnProperty | ||
function has (obj, key) { return hasOwn.call(obj, key) } | ||
var closeRE = RegExp('^(' + [ | ||
@@ -281,0 +279,0 @@ 'area', 'base', 'basefont', 'bgsound', 'br', 'col', 'command', 'embed', |
{ | ||
"name": "hyperx", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "tagged template string virtual dom builder", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37499
38
958
220
2