Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baobab

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baobab - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

bower.json
{
"name": "baobab",
"main": "build/baobab.min.js",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/Yomguithereal/baobab",

@@ -6,0 +6,0 @@ "author": {

# Changelog
## v1.0.1
* Fixing scope argument of `tree.createFacet`.
* Fixing facet mappings edge cases.
* Facets can now use facets.
* Fixing merge edge cases.
* Fixing update edge cases.
* Fixing bug where setting falsy values would fail.
## v1.0.0

@@ -4,0 +13,0 @@

@@ -12,3 +12,3 @@ /**

Object.defineProperty(Baobab, 'version', {
value: '1.0.0'
value: '1.0.1'
});

@@ -15,0 +15,0 @@

{
"name": "baobab",
"version": "1.0.0",
"version": "1.0.1",
"description": "JavaScript data tree with cursors.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,3 +9,3 @@ [![Build Status](https://travis-ci.org/Yomguithereal/baobab.svg)](https://travis-ci.org/Yomguithereal/baobab)

It aims at providing a centralized model holding an application's state and can be paired with **React** easily through mixins or higher order components (available [here](https://github.com/Yomguithereal/baobab-react)).
It aims at providing a centralized model holding an application's state and can be paired with **React** easily through mixins, higher order components, wrapper components or decorators (available [there](https://github.com/Yomguithereal/baobab-react)).

@@ -66,3 +66,3 @@ For a concise introduction about the library and how it can be used in a React/Flux application, you can head toward **@christianalfoni**'s [article](http://christianalfoni.github.io/javascript/2015/02/06/plant-a-baobab-tree-in-your-flux-application.html) on the subject.

```sh
npm install baobab@1.0.0-rc1
npm install baobab

@@ -82,3 +82,3 @@ # Or if you need the latest dev version

```js
bower install baobab@1.0.0-rc1
bower install baobab
```

@@ -459,2 +459,4 @@

**Note**: when using a function or a descriptor object in a path, you are not filtering but rather selecting the first matching element. (It's actually the same as using something like [lodash](https://lodash.com/docs#find)'s `_.find`).
#### Traversal

@@ -637,3 +639,3 @@

// Listening
// Facets are also event emitters
facet.on('update', function() {

@@ -640,0 +642,0 @@ console.log('New value:', facet.get());

@@ -80,4 +80,4 @@ /**

Baobab.prototype.createFacet = function(definition) {
return new Facet(this, definition);
Baobab.prototype.createFacet = function(definition, scope) {
return new Facet(this, definition, scope);
};

@@ -132,3 +132,3 @@

this._transaction = merge(spec, this._transaction);
this._transaction = merge(this._transaction, spec);

@@ -135,0 +135,0 @@ // Should we let the user commit?

@@ -18,3 +18,3 @@ /**

getter = definition.get,
data = null;
facetData = null;

@@ -79,4 +79,2 @@ // Extending event emitter

}
throw Error('baobab.Facet: invalid value returned by function in ' + targetProperty + ' mapping.');
});

@@ -107,3 +105,3 @@ }

if (solved)
return data;
return facetData;

@@ -126,12 +124,26 @@ // Solving

solved = true;
facetData = data;
return data;
return facetData;
};
// Tracking the tree's updates
function cursorsPaths(cursors) {
return Object.keys(cursors).map(function(k) {
return cursors[k].solvedPath;
});
}
function facetsPaths(facets) {
var paths = Object.keys(facets).map(function(k) {
return cursorsPaths(facets[k].cursors);
});
return [].concat.apply([], paths);
}
this.updateHandler = function(e) {
var paths = Object.keys(self.cursors).map(function(k) {
return self.cursors[k].solvedPath;
})
var paths = cursorsPaths(self.cursors).concat(facetsPaths(self.facets));
if (helpers.solveUpdate(e.data.log, paths)) {

@@ -138,0 +150,0 @@ solved = false;

@@ -13,16 +13,12 @@ /**

// TODO: delete every keys
function only(o, n, keep) {
COMMANDS.forEach(function(c) {
if (keep !== c)
delete o[c];
});
o[keep] = n[keep];
function only(command, commandValue) {
var o = {};
o[command] = commandValue;
return o;
}
// Main function
// TODO: use a better way than shallow cloning b?
function merge(a, b) {
var o = helpers.shallowClone(b || {}),
var o = helpers.shallowClone(a || {}),
leafLevel = false,
k,

@@ -32,37 +28,47 @@ i;

COMMANDS.forEach(function(c) {
if (a[c])
only(o, a, c);
if (c in b) {
o = only(c, b[c]);
leafLevel = true;
}
});
if (a.$chain) {
COMMANDS.slice(0, -1).forEach(function(c) {
delete o[c];
});
if (b.$chain) {
if (o.$apply)
o.$apply = helpers.compose(o.$apply, a.$chain);
o.$apply = helpers.compose(o.$apply, b.$chain);
else
o.$apply = a.$chain;
o.$apply = b.$chain;
o = only('$apply', o.$apply);
leafLevel = true;
}
if (a.$splice || o.$splice) {
o.$splice = [].concat(o.$splice || []).concat(a.$splice || []);
if (b.$splice || b.$splice) {
o.$splice = [].concat(o.$splice || []).concat(b.$splice || []);
leafLevel = true;
}
if (a.$push || o.$push) {
o.$push = [].concat(o.$push || []).concat(a.$push || []);
if (b.$push || o.$push) {
o.$push = [].concat(o.$push || []).concat(b.$push || []);
leafLevel = true;
}
if (a.$unshift || o.$unshift) {
o.$unshift = [].concat(a.$unshift || []).concat(o.$unshift || []);
if (b.$unshift || o.$unshift) {
o.$unshift = [].concat(b.$unshift || []).concat(o.$unshift || []);
leafLevel = true;
}
for (k in a) {
if (leafLevel)
return o;
if (type.Object(a[k]))
o[k] = merge(a[k], o[k]);
else if (k[0] !== '$')
o[k] = a[k];
for (k in o) {
if (k.charAt(0) === '$')
delete o[k];
}
for (k in b) {
if (type.Object(b[k]))
o[k] = merge(o[k], b[k]);
}
return o;

@@ -69,0 +75,0 @@ }

@@ -52,3 +52,4 @@ /**

type.Primitive = function(value) {
return typeof value === 'string' ||
return !value ||
typeof value === 'string' ||
typeof value === 'number' ||

@@ -74,4 +75,4 @@ typeof value === 'boolean';

type.Path = function(value) {
var allowed = ['String', 'Number', 'Function', 'Object'];
type.Path = function(value, allowed) {
allowed = allowed || ['String', 'Number', 'Function', 'Object'];

@@ -101,3 +102,3 @@ if (type.Array(value)) {

return type.Path(v) ||
return type.Path(v, ['String', 'Number', 'Object']) ||
v instanceof require('./cursor.js');

@@ -117,4 +118,4 @@ });

});
}
};
module.exports = type;

@@ -23,5 +23,2 @@ /**

if (!type.Object(data) && !type.Array(data))
throw Error('baobab.update: invalid target.');
var log = {};

@@ -38,10 +35,21 @@

lastKey = path[path.length - 1],
oldValue = o[lastKey],
fn,
k,
v;
v,
i,
l;
// If nested object does not exist, we create it
if (type.Primitive(o[lastKey]))
o[lastKey] = {};
else
o[lastKey] = helpers.shallowClone(o[lastKey]);
// Are we at leaf level?
var leafLevel = Object.keys(spec).some(function(k) {
return !!~['$set', '$push', '$unshift', '$splice', '$unset', '$merge', '$apply'].indexOf(k);
return k.charAt(0) === '$';
});
// Leaf level updates
if (leafLevel) {

@@ -70,7 +78,6 @@ log[hash] = true;

o[lastKey] = v;
break;
}
// $apply
if (k === '$apply') {
else if (k === '$apply') {
fn = spec.$apply;

@@ -81,8 +88,7 @@

o[lastKey] = fn.call(null, o[lastKey]);
break;
o[lastKey] = fn.call(null, oldValue);
}
// $merge
if (k === '$merge') {
else if (k === '$merge') {
v = spec.$merge;

@@ -94,3 +100,2 @@

o[lastKey] = helpers.shallowMerge(o[lastKey], v);
break;
}

@@ -105,5 +110,4 @@

v.forEach(function(args) {
o[lastKey] = helpers.splice.apply(null, [o[lastKey]].concat(args));
});
for (i = 0, l = v.length; i < l; i++)
o[lastKey] = helpers.splice.apply(null, [o[lastKey]].concat(v[i]));
}

@@ -135,8 +139,2 @@

// If nested object does not exist, we create it
if (typeof o[lastKey][k] === 'undefined')
o[lastKey][k] = {};
else
o[lastKey][k] = helpers.shallowClone(o[lastKey][k]);
// Recur

@@ -143,0 +141,0 @@ mutator(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc