Comparing version 2.0.0-rc3 to 2.0.0
# Changelog | ||
## v2.0.0 (provisonal) | ||
## v2.0.0 | ||
@@ -12,3 +12,3 @@ * The tree is now immutable by default. | ||
* Adding `cursor.exists`. | ||
* Adding `cursor.watch`. | ||
* Adding `tree.watch`. | ||
* Adding the `pure` option. | ||
@@ -15,0 +15,0 @@ * Changing the way you can define computed data in the tree, aka "facets". Facets are now to be defined within the tree itself, are called "monkeys", and can be accessed using the exact same API as normal data. |
@@ -87,3 +87,3 @@ /** | ||
// Validation behaviour 'rollback' or 'notify' | ||
// Validation behavior 'rollback' or 'notify' | ||
validationBehavior: 'rollback' | ||
@@ -174,2 +174,7 @@ }; | ||
this._refreshMonkeys(); | ||
// Initial validation | ||
var validationError = this.validate(); | ||
if (validationError) throw Error('Baobab: invalid data.', { error: validationError }); | ||
} | ||
@@ -272,2 +277,35 @@ | ||
/** | ||
* Method used to validate the tree's data. | ||
* | ||
* @return {boolean} - Is the tree valid? | ||
*/ | ||
}, { | ||
key: 'validate', | ||
value: function validate(affectedPaths) { | ||
var _options = this.options; | ||
var validate = _options.validate; | ||
var behavior = _options.validationBehavior; | ||
if (typeof validate !== 'function') return null; | ||
var error = validate.call(this, this._previousData, this._data, affectedPaths || [[]]); | ||
if (error instanceof Error) { | ||
if (behavior === 'rollback') { | ||
this._data = this._previousData; | ||
this._affectedPathsIndex = {}; | ||
this._transaction = []; | ||
this._previousData = this._data; | ||
} | ||
this.emit('invalid', { error: error }); | ||
return error; | ||
} | ||
return null; | ||
} | ||
/** | ||
* Method used to select data within the tree by creating a cursor. Cursors | ||
@@ -433,23 +471,7 @@ * are kept as singletons by the tree for performance and hygiene reasons. | ||
// Validation? | ||
var _options = this.options; | ||
var validate = _options.validate; | ||
var behavior = _options.validationBehavior; | ||
// Is the tree still valid? | ||
var validationError = this.validate(affectedPaths); | ||
if (typeof validate === 'function') { | ||
var error = validate.call(this, this._previousData, this._data, affectedPaths); | ||
if (validationError) return this; | ||
if (error instanceof Error) { | ||
this.emit('invalid', { error: error }); | ||
if (behavior === 'rollback') { | ||
this._data = this._previousData; | ||
this._affectedPathsIndex = {}; | ||
this._transaction = []; | ||
this._previousData = this._data; | ||
return this; | ||
} | ||
} | ||
} | ||
// Caching to keep original references before we change them | ||
@@ -562,3 +584,3 @@ var transaction = this._transaction, | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.0.0-rc3' | ||
value: '2.0.0' | ||
}); | ||
@@ -565,0 +587,0 @@ |
{ | ||
"name": "baobab", | ||
"version": "2.0.0-rc3", | ||
"version": "2.0.0", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/baobab.js", |
@@ -51,3 +51,3 @@ /** | ||
// Validation behaviour 'rollback' or 'notify' | ||
// Validation behavior 'rollback' or 'notify' | ||
validationBehavior: 'rollback' | ||
@@ -151,2 +151,8 @@ }; | ||
this._refreshMonkeys(); | ||
// Initial validation | ||
const validationError = this.validate(); | ||
if (validationError) | ||
throw Error('Baobab: invalid data.', {error: validationError}); | ||
} | ||
@@ -249,2 +255,37 @@ | ||
/** | ||
* Method used to validate the tree's data. | ||
* | ||
* @return {boolean} - Is the tree valid? | ||
*/ | ||
validate(affectedPaths) { | ||
const {validate, validationBehavior: behavior} = this.options; | ||
if (typeof validate !== 'function') | ||
return null; | ||
const error = validate.call( | ||
this, | ||
this._previousData, | ||
this._data, | ||
affectedPaths || [[]] | ||
); | ||
if (error instanceof Error) { | ||
if (behavior === 'rollback') { | ||
this._data = this._previousData; | ||
this._affectedPathsIndex = {}; | ||
this._transaction = []; | ||
this._previousData = this._data; | ||
} | ||
this.emit('invalid', {error}); | ||
return error; | ||
} | ||
return null; | ||
} | ||
/** | ||
* Method used to select data within the tree by creating a cursor. Cursors | ||
@@ -425,26 +466,8 @@ * are kept as singletons by the tree for performance and hygiene reasons. | ||
// Validation? | ||
const {validate, validationBehavior: behavior} = this.options; | ||
// Is the tree still valid? | ||
const validationError = this.validate(affectedPaths); | ||
if (typeof validate === 'function') { | ||
const error = validate.call( | ||
this, | ||
this._previousData, | ||
this._data, | ||
affectedPaths | ||
); | ||
if (validationError) | ||
return this; | ||
if (error instanceof Error) { | ||
this.emit('invalid', {error}); | ||
if (behavior === 'rollback') { | ||
this._data = this._previousData; | ||
this._affectedPathsIndex = {}; | ||
this._transaction = []; | ||
this._previousData = this._data; | ||
return this; | ||
} | ||
} | ||
} | ||
// Caching to keep original references before we change them | ||
@@ -550,3 +573,3 @@ const transaction = this._transaction, | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.0.0-rc3' | ||
value: '2.0.0' | ||
}); | ||
@@ -553,0 +576,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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
179127
19
4483