Comparing version 0.2.0 to 0.2.1
@@ -11,3 +11,3 @@ /** | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '0.2.0' | ||
value: '0.2.1' | ||
}); | ||
@@ -14,0 +14,0 @@ |
{ | ||
"name": "baobab", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "JavaScript data tree with cursors.", | ||
@@ -19,4 +19,6 @@ "main": "index.js", | ||
"gulp-uglify": "^1.0.2", | ||
"jsdom": "^1.5.0", | ||
"lodash.clonedeep": "^2.4.1", | ||
"mocha": "^2.0.1", | ||
"react": "^0.12.2", | ||
"vinyl-transform": "^1.0.0" | ||
@@ -23,0 +25,0 @@ }, |
@@ -26,3 +26,3 @@ /** | ||
if (!types.check(initialData, 'object')) | ||
if (!types.check(initialData, 'object|array')) | ||
throw Error('Baobab: invalid data.'); | ||
@@ -206,3 +206,3 @@ | ||
Baobab.prototype.get = function(path) { | ||
Baobab.prototype.reference = function(path) { | ||
var data; | ||
@@ -213,36 +213,18 @@ | ||
if (path) | ||
data = helpers.getIn(this.data, typeof path === 'string' ? [path] : path); | ||
else | ||
data = this.data; | ||
if (!types.check(path, 'path')) | ||
throw Error('Baobab.get: invalid path.'); | ||
return this.options.clone ? this._cloner(data) : data; | ||
return helpers.getIn( | ||
this.data, types.check(path, 'string|number') ? [path] : path | ||
); | ||
}; | ||
Baobab.prototype.reference = function(path) { | ||
var data; | ||
Baobab.prototype.get = function() { | ||
var ref = this.reference.apply(this, arguments); | ||
if (arguments.length > 1) | ||
path = helpers.arrayOf(arguments); | ||
if (path) | ||
data = helpers.getIn(this.data, typeof path === 'string' ? [path] : path); | ||
else | ||
data = this.data; | ||
return data; | ||
return this.options.clone ? this._cloner(ref) : ref; | ||
}; | ||
Baobab.prototype.clone = function(path) { | ||
var data; | ||
if (arguments.length > 1) | ||
path = helpers.arrayOf(arguments); | ||
if (path) | ||
data = helpers.getIn(this.data, typeof path === 'string' ? [path] : path); | ||
else | ||
data = this.data; | ||
return this._cloner(data); | ||
return this._cloner(this.reference.apply(this, arguments)); | ||
}; | ||
@@ -249,0 +231,0 @@ |
@@ -164,3 +164,3 @@ /** | ||
if (path) | ||
if (types.check(path, 'string|number|array')) | ||
return this.root.get(this.path.concat(path)); | ||
@@ -175,3 +175,3 @@ else | ||
if (path) | ||
if (types.check(path, 'string|number|array')) | ||
return this.root.reference(this.path.concat(path)); | ||
@@ -186,3 +186,3 @@ else | ||
if (path) | ||
if (types.check(path, 'string|number|array')) | ||
return this.root.clone(this.path.concat(path)); | ||
@@ -189,0 +189,0 @@ else |
@@ -25,6 +25,7 @@ /** | ||
if (this.cursor) { | ||
if (!types.check(this.cursor, 'string|array|cursor')) | ||
if (!types.check(this.cursor, 'string|number|array|cursor')) | ||
throw Error('baobab.mixin.cursor: invalid data (cursor, string or array).'); | ||
this.cursor = baobab.select(this.cursor); | ||
if (!types.check(this.cursor, 'cursor')) | ||
this.cursor = baobab.select(this.cursor); | ||
this.__type = 'single'; | ||
@@ -34,3 +35,3 @@ } | ||
if (!types.check(this.cursors, 'object|array')) | ||
throw Error('baobab.mixin.cursor: invalid data (cursor, object or array).'); | ||
throw Error('baobab.mixin.cursor: invalid data (object or array).'); | ||
@@ -44,4 +45,5 @@ if (types.check(this.cursors, 'array')) { | ||
else { | ||
// TODO: better validation | ||
for (var k in this.cursors) { | ||
if (!types.check(path, 'cursor')) | ||
if (!types.check(this.cursors[k], 'cursor')) | ||
this.cursors[k] = baobab.select(this.cursors[k]); | ||
@@ -65,3 +67,3 @@ } | ||
}, | ||
componentDidMount: function() { | ||
componentDidMount: function() { | ||
if (this.__type === 'single') { | ||
@@ -77,3 +79,3 @@ this.cursor.on('update', this.__updateHandler); | ||
for (var k in this.cursors) | ||
cursors[k].on('update', this.__updateHandler); | ||
this.cursors[k].on('update', this.__updateHandler); | ||
} | ||
@@ -92,3 +94,3 @@ }, | ||
for (var k in this.cursors) | ||
cursors[k].off('update', this.__updateHandler); | ||
this.cursors[k].off('update', this.__updateHandler); | ||
} | ||
@@ -95,0 +97,0 @@ } |
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
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
40601
13
857