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 2.0.0-dev4 to 2.0.0-dev5

7

dist/baobab.js

@@ -269,4 +269,7 @@ /**

// Applying the operation
var solvedPath = (0, _helpers.solvePath)(this.data, path);
var _getIn = (0, _helpers.getIn)(this.data, path, this._computedDataIndex);
var solvedPath = _getIn.solvedPath;
// If we couldn't solve the path, we throw

@@ -437,3 +440,3 @@ if (!solvedPath) throw (0, _helpers.makeError)('Baobab.update: could not solve the given path.', {

Object.defineProperty(Baobab, 'version', {
value: '2.0.0-dev4'
value: '2.0.0-dev5'
});

@@ -440,0 +443,0 @@

@@ -107,3 +107,3 @@ /**

if (!this._dynamicPath) this.solvedPath = this.path;else this.solvedPath = (0, _helpers.solvePath)(this.tree.data, this.path);
if (!this._dynamicPath) this.solvedPath = this.path;else this.solvedPath = (0, _helpers.getIn)(this.tree.data, this.path, this.tree._computedDataIndex).solvedPath;

@@ -120,3 +120,3 @@ /**

var record = (0, _helpers.getIn)(previousData, _this.solvedPath);
var record = (0, _helpers.getIn)(previousData, _this.solvedPath).data;

@@ -155,6 +155,6 @@ if (_this.state.recording && !_this.state.undoing) _this.archive.add(record);

// Checking whether we should keep track of some dependencies
var additionalPaths = _this._facetPath ? (0, _helpers.getIn)(_this.tree._computedDataIndex, _this._facetPath).relatedPaths() : [];
var additionalPaths = _this._facetPath ? (0, _helpers.getIn)(_this.tree._computedDataIndex, _this._facetPath).data.relatedPaths() : [];
// If the cursor's path is dynamic, we need to recompute it
if (_this._dynamicPath) _this.solvedPath = (0, _helpers.solvePath)(_this.tree.data, _this.path);
if (_this._dynamicPath) _this.solvedPath = (0, _helpers.getIn)(_this.tree.data, _this.path, _this._computedDataIndex).solvedPath;

@@ -167,3 +167,3 @@ comparedPaths = [_this.solvedPath].concat(additionalPaths);

comparedPaths = _this._watchedPaths.reduce(function (cp, p) {
if (_type2['default'].dynamicPath(p)) p = (0, _helpers.solvePath)(_this.tree.data, p);
if (_type2['default'].dynamicPath(p)) p = (0, _helpers.getIn)(_this.tree.data, p, _this._computedDataIndex).solvedPath;

@@ -174,3 +174,3 @@ if (!p) return cp;

if (facetPath) return cp.concat((0, _helpers.getIn)(_this.tree._computedDataIndex, p).relatedPaths());
if (facetPath) return cp.concat((0, _helpers.getIn)(_this.tree._computedDataIndex, p).data.relatedPaths());

@@ -424,9 +424,5 @@ return cp.concat([p]);

var fullPath = this.solvedPath && this.solvedPath.concat(path);
if (!this.solvedPath) return { data: undefined, solvedPath: null };
var data = undefined;
if (!fullPath) data = undefined;else data = (0, _helpers.getIn)(this.tree.data, fullPath, this.tree._computedDataIndex, this.tree.options);
return { data: data, solvedPath: fullPath };
return (0, _helpers.getIn)(this.tree.data, this.solvedPath.concat(path), this.tree._computedDataIndex, this.tree.options);
}

@@ -460,3 +456,3 @@ }, {

// Emitting the event
if (solvedPath) this.tree.emit('get', { data: data, path: solvedPath });
this.tree.emit('get', { data: data, solvedPath: solvedPath, path: this.path.concat(path) });

@@ -463,0 +459,0 @@ return data;

@@ -113,3 +113,3 @@ /**

// Solving recursive path
var relatedFacet = (0, _helpers.getIn)(_this2.tree._computedDataIndex, facetPath);
var relatedFacet = (0, _helpers.getIn)(_this2.tree._computedDataIndex, facetPath).data;

@@ -116,0 +116,0 @@ return paths.concat(relatedFacet.relatedPaths());

@@ -21,3 +21,2 @@ /**

exports.pathObject = pathObject;
exports.solvePath = solvePath;
exports.solveUpdate = solveUpdate;

@@ -252,19 +251,2 @@ exports.splice = splice;

/**
* Function returning the first element of a list matching the given
* predicate.
*
* @param {array} a - The target array.
* @param {function} fn - The predicate function.
* @return {mixed} - The first matching item or `undefined`.
*/
function first(a, fn) {
var i = undefined,
l = undefined;
for (i = 0, l = a.length; i < l; i++) {
if (fn(a[i])) return a[i];
}
return;
}
/**
* Function freezing the given variable if possible.

@@ -327,3 +309,3 @@ *

*/
function solveMask(immutable, data, mask, parent, lastKey) {
function solveMask(immutable, data, mask, parent) {
for (var k in mask) {

@@ -342,3 +324,3 @@ if (k[0] === '$') {

}
solveMask(immutable, data[k], mask[k], data, k);
solveMask(immutable, data[k], mask[k], data);
}

@@ -360,4 +342,7 @@ }

* @param {object} [mask] - An optional computed data index.
* @return {mixed} - The data at path, or if not found, `undefined`.
* @return {object} result - The result.
* @return {mixed} result.data - The data at path, or `undefined`.
* @return {array} result.solvedPath - The solved path or `null`.
*/
var notFoundObject = { data: undefined, solvedPath: null };

@@ -370,4 +355,6 @@ function getIn(object, path) {

var c = object,
var solvedPath = [],
c = object,
cm = mask,
idx = undefined,
i = undefined,

@@ -377,15 +364,24 @@ l = undefined;

for (i = 0, l = path.length; i < l; i++) {
if (!c) return;
if (!c) return { data: undefined, solvedPath: path };
if (typeof path[i] === 'function') {
if (!_type2['default'].array(c)) return;
if (!_type2['default'].array(c)) return notFoundObject;
c = first(c, path[i]);
idx = index(c, path[i]);
if (! ~idx) return notFoundObject;
solvedPath.push(idx);
c = c[idx];
} else if (typeof path[i] === 'object') {
if (!_type2['default'].array(c)) return;
if (!_type2['default'].array(c)) return notFoundObject;
c = first(c, function (e) {
idx = index(c, function (e) {
return compare(e, path[i]);
});
if (! ~idx) return notFoundObject;
solvedPath.push(idx);
c = c[idx];
} else {
solvedPath.push(path[i]);

@@ -396,4 +392,2 @@ // Solving data from a facet if needed

cm = null;
if (opts.immutable) deepFreeze(c);
} else {

@@ -414,3 +408,3 @@ c = c[path[i]];

return c;
return { data: c, solvedPath: solvedPath };
}

@@ -546,47 +540,2 @@

/**
* Function solving the given path within the target object.
*
* @param {object} object - The object in which the path must be solved.
* @param {array} path - The path to follow.
* @return {mixed} - The solved path if possible, else `null`.
*/
function solvePath(object, path) {
var solvedPath = [],
c = object,
idx = undefined,
i = undefined,
l = undefined;
for (i = 0, l = path.length; i < l; i++) {
if (!c) return null;
if (typeof path[i] === 'function') {
if (!_type2['default'].array(c)) return;
idx = index(c, path[i]);
if (! ~idx) return null;
solvedPath.push(idx);
c = c[idx];
} else if (typeof path[i] === 'object') {
if (!_type2['default'].array(c)) return;
idx = index(c, function (e) {
return compare(e, path[i]);
});
if (! ~idx) return null;
solvedPath.push(idx);
c = c[idx];
} else {
solvedPath.push(path[i]);
c = c[path[i]] || {};
}
}
return solvedPath;
}
/**
* Function determining whether some paths in the tree were affected by some

@@ -636,2 +585,3 @@ * updates that occurred at the given paths. This helper is mainly used at

// If path is not relevant, we break
// NOTE: the '!=' instead of '!==' is required here!
if (s != p[k]) break;

@@ -638,0 +588,0 @@

{
"name": "baobab",
"version": "2.0.0-dev4",
"version": "2.0.0-dev5",
"description": "JavaScript persistent data tree with cursors.",

@@ -5,0 +5,0 @@ "main": "./dist/baobab.js",

@@ -15,2 +15,3 @@ /**

deepFreeze,
getIn,
makeError,

@@ -20,3 +21,2 @@ deepMerge,

shallowMerge,
solvePath,
uniqid

@@ -258,3 +258,7 @@ } from './helpers';

// Applying the operation
const solvedPath = solvePath(this.data, path);
const {solvedPath} = getIn(
this.data,
path,
this._computedDataIndex
);

@@ -422,3 +426,3 @@ // If we couldn't solve the path, we throw

Object.defineProperty(Baobab, 'version', {
value: '2.0.0-dev4'
value: '2.0.0-dev5'
});

@@ -425,0 +429,0 @@

@@ -17,3 +17,2 @@ /**

shallowClone,
solvePath,
solveUpdate

@@ -98,3 +97,7 @@ } from './helpers';

else
this.solvedPath = solvePath(this.tree.data, this.path);
this.solvedPath = getIn(
this.tree.data,
this.path,
this.tree._computedDataIndex
).solvedPath;

@@ -112,3 +115,3 @@ /**

const record = getIn(previousData, this.solvedPath);
const record = getIn(previousData, this.solvedPath).data;

@@ -147,3 +150,5 @@ if (this.state.recording && !this.state.undoing)

const additionalPaths = this._facetPath ?
getIn(this.tree._computedDataIndex, this._facetPath).relatedPaths() :
getIn(this.tree._computedDataIndex, this._facetPath)
.data
.relatedPaths() :
[];

@@ -153,3 +158,7 @@

if (this._dynamicPath)
this.solvedPath = solvePath(this.tree.data, this.path);
this.solvedPath = getIn(
this.tree.data,
this.path,
this._computedDataIndex
).solvedPath;

@@ -163,3 +172,7 @@ comparedPaths = [this.solvedPath].concat(additionalPaths);

if (type.dynamicPath(p))
p = solvePath(this.tree.data, p);
p = getIn(
this.tree.data,
p,
this._computedDataIndex
).solvedPath;

@@ -173,3 +186,3 @@ if (!p)

return cp.concat(
getIn(this.tree._computedDataIndex, p).relatedPaths());
getIn(this.tree._computedDataIndex, p).data.relatedPaths());

@@ -417,17 +430,11 @@ return cp.concat([p]);

_get(path=[]) {
const fullPath = this.solvedPath && this.solvedPath.concat(path);
if (!this.solvedPath)
return {data: undefined, solvedPath: null};
let data;
if (!fullPath)
data = undefined;
else
data = getIn(
this.tree.data,
fullPath,
this.tree._computedDataIndex,
this.tree.options
);
return {data, solvedPath: fullPath};
return getIn(
this.tree.data,
this.solvedPath.concat(path),
this.tree._computedDataIndex,
this.tree.options
);
}

@@ -457,4 +464,3 @@

// Emitting the event
if (solvedPath)
this.tree.emit('get', {data, path: solvedPath});
this.tree.emit('get', {data, solvedPath, path: this.path.concat(path)});

@@ -461,0 +467,0 @@ return data;

@@ -100,3 +100,3 @@ /**

// Solving recursive path
const relatedFacet = getIn(this.tree._computedDataIndex, facetPath);
const relatedFacet = getIn(this.tree._computedDataIndex, facetPath).data;

@@ -103,0 +103,0 @@ return paths.concat(relatedFacet.relatedPaths());

@@ -218,19 +218,2 @@ /**

/**
* Function returning the first element of a list matching the given
* predicate.
*
* @param {array} a - The target array.
* @param {function} fn - The predicate function.
* @return {mixed} - The first matching item or `undefined`.
*/
function first(a, fn) {
let i, l;
for (i = 0, l = a.length; i < l; i++) {
if (fn(a[i]))
return a[i];
}
return;
}
/**
* Function freezing the given variable if possible.

@@ -300,3 +283,3 @@ *

*/
function solveMask(immutable, data, mask, parent, lastKey) {
function solveMask(immutable, data, mask, parent) {
for (let k in mask) {

@@ -318,3 +301,3 @@ if (k[0] === '$') {

}
solveMask(immutable, data[k], mask[k], data, k);
solveMask(immutable, data[k], mask[k], data);
}

@@ -336,9 +319,15 @@ }

* @param {object} [mask] - An optional computed data index.
* @return {mixed} - The data at path, or if not found, `undefined`.
* @return {object} result - The result.
* @return {mixed} result.data - The data at path, or `undefined`.
* @return {array} result.solvedPath - The solved path or `null`.
*/
const notFoundObject = {data: undefined, solvedPath: null};
export function getIn(object, path, mask=null, opts={}) {
path = path || [];
let c = object,
let solvedPath = [],
c = object,
cm = mask,
idx,
i,

@@ -349,17 +338,28 @@ l;

if (!c)
return;
return {data: undefined, solvedPath: path};
if (typeof path[i] === 'function') {
if (!type.array(c))
return;
return notFoundObject;
c = first(c, path[i]);
idx = index(c, path[i]);
if (!~idx)
return notFoundObject;
solvedPath.push(idx);
c = c[idx];
}
else if (typeof path[i] === 'object') {
if (!type.array(c))
return;
return notFoundObject;
c = first(c, e => compare(e, path[i]));
idx = index(c, e => compare(e, path[i]));
if (!~idx)
return notFoundObject;
solvedPath.push(idx);
c = c[idx];
}
else {
solvedPath.push(path[i]);

@@ -370,5 +370,2 @@ // Solving data from a facet if needed

cm = null;
if (opts.immutable)
deepFreeze(c);
}

@@ -391,3 +388,3 @@ else {

return c;
return {data: c, solvedPath};
}

@@ -522,51 +519,2 @@

/**
* Function solving the given path within the target object.
*
* @param {object} object - The object in which the path must be solved.
* @param {array} path - The path to follow.
* @return {mixed} - The solved path if possible, else `null`.
*/
export function solvePath(object, path) {
let solvedPath = [],
c = object,
idx,
i,
l;
for (i = 0, l = path.length; i < l; i++) {
if (!c)
return null;
if (typeof path[i] === 'function') {
if (!type.array(c))
return;
idx = index(c, path[i]);
if (!~idx)
return null;
solvedPath.push(idx);
c = c[idx];
}
else if (typeof path[i] === 'object') {
if (!type.array(c))
return;
idx = index(c, e => compare(e, path[i]));
if (!~idx)
return null;
solvedPath.push(idx);
c = c[idx];
}
else {
solvedPath.push(path[i]);
c = c[path[i]] || {};
}
}
return solvedPath;
}
/**
* Function determining whether some paths in the tree were affected by some

@@ -609,2 +557,3 @@ * updates that occurred at the given paths. This helper is mainly used at

// If path is not relevant, we break
// NOTE: the '!=' instead of '!==' is required here!
if (s != p[k])

@@ -611,0 +560,0 @@ break;

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