Comparing version 0.0.0-alpha.0a71f0d4 to 0.0.0-alpha.0a71f0d4-alpha.1fae31d4
@@ -1,6 +0,6 @@ | ||
import merge from 'merge-deep'; | ||
import clone from 'clone'; | ||
class Node { | ||
constructor(props) { | ||
merge(this, props); | ||
constructor(value) { | ||
this.value = clone(value); | ||
this.parent = null; | ||
@@ -7,0 +7,0 @@ this.children = []; |
14
index.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('merge-deep')) : | ||
typeof define === 'function' && define.amd ? define(['merge-deep'], factory) : | ||
(global.arbreNode = factory(global.merge)); | ||
}(this, (function (merge) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('clone')) : | ||
typeof define === 'function' && define.amd ? define(['clone'], factory) : | ||
(global.arbreNode = factory(global.clone)); | ||
}(this, (function (clone) { 'use strict'; | ||
merge = 'default' in merge ? merge['default'] : merge; | ||
clone = 'default' in clone ? clone['default'] : clone; | ||
class Node { | ||
constructor(props) { | ||
merge(this, props); | ||
constructor(value) { | ||
this.value = clone(value); | ||
this.parent = null; | ||
@@ -13,0 +13,0 @@ this.children = []; |
@@ -1,6 +0,6 @@ | ||
import merge from 'merge-deep' | ||
import clone from 'clone' | ||
export default class Node { | ||
constructor(props) { | ||
merge(this, props) | ||
constructor(value) { | ||
this.value = clone(value) | ||
this.parent = null | ||
@@ -7,0 +7,0 @@ this.children = [] |
{ | ||
"name": "arbre-node", | ||
"version": "0.0.0-alpha.0a71f0d4", | ||
"version": "0.0.0-alpha.0a71f0d4-alpha.1fae31d4", | ||
"main": "index.js", | ||
@@ -23,3 +23,6 @@ "jsnext:main": "index.es.js", | ||
"build": "simple" | ||
}, | ||
"dependencies": { | ||
"clone": "^1.0.2" | ||
} | ||
} |
import test from 'ava' | ||
import Node from '../lib/node' | ||
test('mix props into node', t => { | ||
const node = new Node({ foo: 'bar' }) | ||
test('set value', t => { | ||
const value = 'foo' | ||
const node = new Node(value) | ||
t.is(node.foo, 'bar') | ||
t.is(node.value, value) | ||
}) | ||
test('clone props', t => { | ||
const props = { foo: { bar: 'baz' }} | ||
const node = new Node(props) | ||
test('clone value', t => { | ||
const value = { foo: { bar: 'baz' }} | ||
const node = new Node(value) | ||
t.not(node.foo, props.foo) | ||
t.deepEqual(node.foo, props.foo) | ||
t.not(node.value, value) | ||
t.not(node.value.foo, value.foo) | ||
t.deepEqual(node.value, value) | ||
}) | ||
test('set undefined value by default', t => { | ||
const node = new Node() | ||
t.is(node.value, undefined) | ||
}) | ||
test('set parent to null', t => { | ||
const node = new Node() | ||
t.is(node.parent, null) | ||
}) | ||
test('set children to empty array', t => { | ||
const node = new Node() | ||
t.true(Array.isArray(node.children)) | ||
t.is(node.children.length, 0) | ||
}) |
1973
57
1
+ Addedclone@^1.0.2
+ Addedclone@1.0.4(transitive)