Comparing version 1.8.1 to 1.9.0
{ | ||
"name": "vsvg", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"description": "A minimal implementation of a vdom that allows for quick server or client side rendering of svg's", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,10 +22,10 @@ | ||
function SvgNode( tagName, attributes ) { | ||
function SvgNode( tagName, attributes, vnodes ) { | ||
var rest = utils.makeArray( arguments, 2 ); | ||
if ( !( this instanceof SvgNode ) ) { // magical invocation | ||
return new SvgNode( tagName, attributes ); | ||
return new SvgNode( tagName, attributes, rest ); | ||
} | ||
attributes = Object.create( attributes || {} ); | ||
this.guid = utils.guid(); | ||
@@ -49,4 +49,18 @@ this.tagName = tagName; | ||
} | ||
if ( Array.isArray( vnodes ) && vnodes.length ) { | ||
vnodes.filter( SvgNode.isNode ).forEach( this.appendChild.bind( this ) ); | ||
} | ||
} | ||
/* | ||
SvgNode.isNode - checks to see if node is a instance of SvgNode | ||
params | ||
vnode { Mixed } - a value to test against the instance of SvgNode | ||
*/ | ||
SvgNode.isNode = function( vnode ) { | ||
return vnode instanceof SvgNode; | ||
}; | ||
SvgNode.prototype = { | ||
@@ -53,0 +67,0 @@ |
@@ -156,4 +156,4 @@ | ||
exports.makeArray = function makeArray( arr ) { | ||
return Array.prototype.slice.call( arr, 0 ); | ||
}; | ||
exports.makeArray = function makeArray( arr, index ) { | ||
return Array.prototype.slice.call( arr, index || 0 ); | ||
}; |
var test = require( 'tape' ), | ||
vsvg = require( '../src/' ); | ||
vsvg = require( '../src/' ), | ||
SvgNode = require( '../src/svgNode' ); | ||
test( 'testing element creation', function( t ) { | ||
var svg = vsvg.svg(); | ||
var path = vsvg.path(), | ||
g = vsvg.path(), | ||
svg = vsvg.svg( { | ||
xmlns: 'http://www.w3.org/2000/svg' | ||
}, g, path ); | ||
// test out some of the properties of new element | ||
@@ -10,3 +15,5 @@ t.equals( typeof svg.guid, 'string', 'property guid is a string' ); | ||
t.equals( Array.isArray( svg.children ), true, 'property children is an array' ); | ||
t.equals( svg.children.length, 0, 'property children startes empty' ); | ||
t.equals( svg.children.length, 2, 'property children startes empty' ); | ||
t.equals( svg.children[ 0 ].guid, g.guid, 'the element is passed in the second argument is the appended to the children in the correct position' ); | ||
t.equals( svg.children[ 1 ].guid, path.guid, 'the element is passed in the third argument is the appended to the children in the correct position' ); | ||
t.equals( typeof svg.insertBefore, 'function', 'property insertBefore is a function' ); | ||
@@ -19,2 +26,3 @@ t.equals( typeof svg.appendChild, 'function', 'property appendChild is a function' ); | ||
t.equals( typeof svg.attributes, 'object', 'property attributes is an object' ); | ||
t.equals( svg.attributes.xmlns, 'http://www.w3.org/2000/svg', 'attributes that are passed in the first argument is applied to the attributes object' ); | ||
t.equals( typeof svg.outerHTML, 'string', 'property outerHTML is a string' ); | ||
@@ -234,2 +242,9 @@ t.equals( typeof svg.innerHTML, 'string', 'property innerHTML is a string' ); | ||
} ); | ||
} ); | ||
test( 'testings SvgNode.isNode', function( t ) { | ||
var svg = vsvg.svg(); | ||
t.equals( SvgNode.isNode( svg ), true, 'SvgNode.isNode will return true id a SvgNode is given in the first parameter' ); | ||
t.equals( SvgNode.isNode( {} ), false, 'SvgNode.isNode will return true id a SvgNode is given in the first parameter' ); | ||
t.end(); | ||
} ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
110874
1726