Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "baobab", | ||
"main": "build/baobab.min.js", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/Yomguithereal/baobab", | ||
@@ -10,3 +10,3 @@ "author": { | ||
}, | ||
"description": "JavaScript data tree with cursors.", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
"keywords": [ | ||
@@ -13,0 +13,0 @@ "cursors", |
# Changelog | ||
## v1.0.2 | ||
* Fixing facets related issues (internal). | ||
* Fixing cases where falsy paths in cursors setters would fail the update. | ||
* Fixing `$splice` behavior. | ||
* Fixing `$merge` behavior. | ||
* Persistent history rather than deep cloned. | ||
* Improving performances on single update cases. | ||
## v1.0.1 | ||
@@ -4,0 +13,0 @@ |
@@ -12,3 +12,3 @@ /** | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '1.0.1' | ||
value: '1.0.2' | ||
}); | ||
@@ -15,0 +15,0 @@ |
{ | ||
"name": "baobab", | ||
"version": "1.0.1", | ||
"description": "JavaScript data tree with cursors.", | ||
"version": "1.0.2", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -5,3 +5,3 @@ [![Build Status](https://travis-ci.org/Yomguithereal/baobab.svg)](https://travis-ci.org/Yomguithereal/baobab) | ||
**Baobab** is a JavaScript data tree supporting cursors and enabling developers to easily navigate and monitor nested data. | ||
**Baobab** is a JavaScript [persistent](http://en.wikipedia.org/wiki/Persistent_data_structure) data tree supporting cursors and enabling developers to easily navigate and monitor nested data. | ||
@@ -803,3 +803,3 @@ It is mainly inspired by functional [zippers](http://clojuredocs.org/clojure.zip/zipper) such as Clojure's ones and by [Om](https://github.com/swannodette/om)'s cursors. | ||
*Immutable behaviour* | ||
**Immutable behaviour** | ||
@@ -806,0 +806,0 @@ TL;DR: Don't mutate things in your *baobab* tree. Let the tree handle its own mutations. |
@@ -75,15 +75,12 @@ /** | ||
*/ | ||
Baobab.prototype.addFacet = function(name, definition) { | ||
this.facets[name] = this.createFacet(definition); | ||
Baobab.prototype.addFacet = function(name, definition, args) { | ||
this.facets[name] = this.createFacet(definition, args); | ||
return this; | ||
}; | ||
Baobab.prototype.createFacet = function(definition, scope) { | ||
return new Facet(this, definition, scope); | ||
Baobab.prototype.createFacet = function(definition, args) { | ||
return new Facet(this, definition, args); | ||
}; | ||
Baobab.prototype.select = function(path) { | ||
if (!path) | ||
throw Error('Baobab.select: invalid path.'); | ||
if (arguments.length > 1) | ||
@@ -126,3 +123,3 @@ path = helpers.arrayOf(arguments); | ||
Baobab.prototype.stack = function(spec) { | ||
Baobab.prototype.stack = function(spec, skipMerge) { | ||
var self = this; | ||
@@ -133,3 +130,5 @@ | ||
this._transaction = merge(this._transaction, spec); | ||
this._transaction = (skipMerge && !Object.keys(this._transaction).length) ? | ||
spec : | ||
merge(this._transaction, spec); | ||
@@ -136,0 +135,0 @@ // Should we let the user commit? |
@@ -47,5 +47,3 @@ /** | ||
// Handle archive | ||
var data = helpers.getIn(previousState, self.solvedPath, self.tree), | ||
record = helpers.deepClone(data); | ||
var record = helpers.getIn(previousState, self.solvedPath, self.tree); | ||
self.archive.add(record); | ||
@@ -227,3 +225,10 @@ } | ||
if (arguments.length < 4) { | ||
if (method === 'unset') { | ||
val = true; | ||
if (arguments.length === 2) | ||
key = []; | ||
} | ||
else if (arguments.length < 4) { | ||
val = key; | ||
@@ -233,3 +238,4 @@ key = []; | ||
key = key || []; | ||
if (!type.Path(key)) | ||
throw Error('baobab.Cursor.' + method + ': invalid path "' + key + '".'); | ||
@@ -267,3 +273,3 @@ // Splice exception | ||
return this.update(spec); | ||
return this.update(spec, true); | ||
}; | ||
@@ -284,21 +290,12 @@ } | ||
var spec = pathPolymorphism.bind(this, 'unset', null).apply(this, [key, true]); | ||
var spec = pathPolymorphism.bind(this, 'unset', null).apply(this, arguments); | ||
return this.update(spec); | ||
return this.update(spec, true); | ||
}; | ||
Cursor.prototype.update = function(key, spec) { | ||
if (arguments.length < 2) { | ||
this.tree.stack(helpers.pathObject(this.solvedPath, key)); | ||
return this; | ||
} | ||
Cursor.prototype.update = function(spec, skipMerge) { | ||
if (!type.Object(spec)) | ||
throw Error('baobab.Cursor.update: invalid specifications.'); | ||
// Solving path | ||
var path = [].concat(key), | ||
solvedPath = helpers.solvePath(this.get(), path, this.tree); | ||
if (!solvedPath) | ||
throw Error('baobab.Cursor.update: could not solve dynamic path.'); | ||
this.tree.stack(helpers.pathObject(this.solvedPath.concat(solvedPath), spec)); | ||
this.tree.stack(helpers.pathObject(this.solvedPath, spec), skipMerge); | ||
return this; | ||
@@ -305,0 +302,0 @@ }; |
@@ -12,3 +12,3 @@ /** | ||
function Facet(tree, definition, scope) { | ||
function Facet(tree, definition, args) { | ||
var self = this; | ||
@@ -35,3 +35,3 @@ | ||
// Refreshing the internal mapping | ||
function refresh(complexity, targetMapping, targetProperty, mappingType) { | ||
function refresh(complexity, targetMapping, targetProperty, mappingType, refreshArgs) { | ||
if (!complexity && !firstTime) | ||
@@ -45,3 +45,3 @@ return; | ||
if (complexity) | ||
solvedMapping = targetMapping.call(scope); | ||
solvedMapping = targetMapping.apply(this, refreshArgs); | ||
@@ -76,3 +76,3 @@ if (!mappingType(solvedMapping)) | ||
if (!self.facets) | ||
if (!self.facets[k]) | ||
throw Error('baobab.Facet: unkown "' + solvedMapping[k] + '" facet in facets mapping.'); | ||
@@ -85,4 +85,8 @@ return; | ||
this.refresh = function() { | ||
this.refresh = function(refreshArgs) { | ||
refreshArgs = refreshArgs || []; | ||
if (!type.Array(refreshArgs)) | ||
throw Error('baobab.Facet.refresh: first argument should be an array.'); | ||
if (cursorsMapping) | ||
@@ -93,3 +97,4 @@ refresh( | ||
'cursors', | ||
type.FacetCursors | ||
type.FacetCursors, | ||
refreshArgs | ||
); | ||
@@ -102,3 +107,4 @@ | ||
'facets', | ||
type.FacetFacets | ||
type.FacetFacets, | ||
refreshArgs | ||
); | ||
@@ -159,3 +165,3 @@ }; | ||
// Init routine | ||
this.refresh(); | ||
this.refresh(args); | ||
this.tree.on('update', this.updateHandler); | ||
@@ -162,0 +168,0 @@ |
@@ -26,8 +26,6 @@ /** | ||
index = +index; | ||
nb = +nb; | ||
return array | ||
.slice(0, index) | ||
.concat(array.slice(index + nb).concat(elements)); | ||
.concat(elements) | ||
.concat(array.slice(index + nb)); | ||
} | ||
@@ -34,0 +32,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
// Helpers | ||
var COMMANDS = ['$unset', '$set', '$merge', '$apply']; | ||
var COMMANDS = ['$unset', '$set', '$apply']; | ||
@@ -45,2 +45,7 @@ function only(command, commandValue) { | ||
if (b.$merge) { | ||
o.$merge = helpers.shallowMerge(o.$merge || {}, b.$merge); | ||
leafLevel = true; | ||
} | ||
if (b.$splice || b.$splice) { | ||
@@ -47,0 +52,0 @@ o.$splice = [].concat(o.$splice || []).concat(b.$splice || []); |
@@ -79,4 +79,4 @@ /** | ||
// $apply | ||
else if (k === '$apply') { | ||
fn = spec.$apply; | ||
else if (k === '$apply' || k === '$chain') { | ||
fn = spec.$apply || spec.$chain; | ||
@@ -83,0 +83,0 @@ if (typeof fn !== 'function') |
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
59837
15
1245