Comparing version 2.0.0-dev7 to 2.0.0-dev8
@@ -8,4 +8,6 @@ # Changelog | ||
* Adding `cursor.concat`. | ||
* Adding the `cursor.serialize` method. | ||
* Adding the `cursor.project` method. | ||
* Adding `cursor.serialize`. | ||
* Adding `cursor.project`. | ||
* Adding `cursor.exists`. | ||
* Adding `cursor.watch`. | ||
* Changing the way you can define computed data in the tree, aka "facets". Facets are now to be defined within the tree itself and can be accessed using the exact same API as normal data. | ||
@@ -12,0 +14,0 @@ * Adding an alternative facet definition syntax for convenience. |
@@ -141,3 +141,3 @@ /** | ||
['apply', 'concat', 'get', 'push', 'merge', 'project', 'serialize', 'set', 'splice', 'unset', 'unshift'].forEach(bootstrap); | ||
['apply', 'concat', 'exists', 'get', 'push', 'merge', 'project', 'serialize', 'set', 'splice', 'unset', 'unshift'].forEach(bootstrap); | ||
@@ -447,3 +447,3 @@ // Creating the computed data index for the first time | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.0.0-dev7' | ||
value: '2.0.0-dev8' | ||
}); | ||
@@ -450,0 +450,0 @@ |
@@ -111,3 +111,3 @@ /** | ||
if (!this._dynamicPath) this.solvedPath = this.path;else this.solvedPath = (0, _helpers.getIn)(this.tree.data, this.path, this.tree._computedDataIndex).solvedPath; | ||
if (!this._dynamicPath) this.solvedPath = this.path;else this.solvedPath = this._getIn(this.path).solvedPath; | ||
@@ -125,3 +125,3 @@ /** | ||
_this.solvedPath = (0, _helpers.getIn)(_this.tree.data, _this.path, _this._computedDataIndex).solvedPath; | ||
_this.solvedPath = _this._getIn(_this.path).solvedPath; | ||
}; | ||
@@ -195,3 +195,3 @@ | ||
_createClass(Cursor, [{ | ||
key: '_getComparedPaths', | ||
key: '_getIn', | ||
@@ -204,2 +204,15 @@ /** | ||
/** | ||
* Curried version of the `getIn` helper and ready to serve a cursor instance | ||
* purpose without having to write endlessly the same args over and over. | ||
* | ||
* @param {array} path - The path to get in the tree. | ||
* @return {object} - The result of the `getIn` helper. | ||
*/ | ||
value: function _getIn(path) { | ||
return (0, _helpers.getIn)(this.tree.data, path, this.tree._computedDataIndex, this.tree.options); | ||
} | ||
}, { | ||
key: '_getComparedPaths', | ||
/** | ||
* Method returning the paths of the tree watched over by the cursor and that | ||
@@ -227,3 +240,3 @@ * should be taken into account when solving a potential update. | ||
comparedPaths = this._watchedPaths.reduce(function (cp, p) { | ||
if (_type2['default'].dynamicPath(p)) p = (0, _helpers.getIn)(_this2.tree.data, p, _this2._computedDataIndex).solvedPath; | ||
if (_type2['default'].dynamicPath(p)) p = _this2._getIn(p).solvedPath; | ||
@@ -461,7 +474,31 @@ if (!p) return cp; | ||
if (!this.solvedPath) return { data: undefined, solvedPath: null }; | ||
if (!_type2['default'].path(path)) throw (0, _helpers.makeError)('Baobab.Cursor.getters: invalid path.', { path: path }); | ||
return (0, _helpers.getIn)(this.tree.data, this.solvedPath.concat(path), this.tree._computedDataIndex, this.tree.options); | ||
if (!this.solvedPath) return { data: undefined, solvedPath: null, exists: false }; | ||
return this._getIn(this.solvedPath.concat(path)); | ||
} | ||
}, { | ||
key: 'exists', | ||
/** | ||
* Method used to check whether a certain path exists in the tree starting | ||
* from the current cursor. | ||
* | ||
* Arity (1): | ||
* @param {path} path - Path to check in the tree. | ||
* | ||
* Arity (2): | ||
* @param {..step} path - Path to check in the tree. | ||
* | ||
* @return {boolean} - Does the given path exists? | ||
*/ | ||
value: function exists(path) { | ||
path = path || path === 0 ? path : []; | ||
if (arguments.length > 1) path = (0, _helpers.arrayFrom)(arguments); | ||
return this._get(path).exists; | ||
} | ||
}, { | ||
key: 'get', | ||
@@ -478,3 +515,3 @@ | ||
* Arity (2): | ||
* @param {..step} path - Path to get in the tree. | ||
* @param {..step} path - Path to get in the tree. | ||
* | ||
@@ -481,0 +518,0 @@ * @return {mixed} - Data at path. |
@@ -348,3 +348,3 @@ /** | ||
path = path || []; | ||
if (!path) return notFoundObject; | ||
@@ -401,3 +401,3 @@ var solvedPath = [], | ||
return { data: c, solvedPath: solvedPath, exists: true }; | ||
return { data: c, solvedPath: solvedPath, exists: c !== undefined }; | ||
} | ||
@@ -404,0 +404,0 @@ |
{ | ||
"name": "baobab", | ||
"version": "2.0.0-dev7", | ||
"version": "2.0.0-dev8", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/baobab.js", |
@@ -117,2 +117,3 @@ /** | ||
'concat', | ||
'exists', | ||
'get', | ||
@@ -431,3 +432,3 @@ 'push', | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.0.0-dev7' | ||
value: '2.0.0-dev8' | ||
}); | ||
@@ -434,0 +435,0 @@ |
@@ -100,7 +100,3 @@ /** | ||
else | ||
this.solvedPath = getIn( | ||
this.tree.data, | ||
this.path, | ||
this.tree._computedDataIndex | ||
).solvedPath; | ||
this.solvedPath = this._getIn(this.path).solvedPath; | ||
@@ -117,7 +113,3 @@ /** | ||
this.solvedPath = getIn( | ||
this.tree.data, | ||
this.path, | ||
this._computedDataIndex | ||
).solvedPath; | ||
this.solvedPath = this._getIn(this.path).solvedPath; | ||
}; | ||
@@ -200,2 +192,18 @@ | ||
/** | ||
* Curried version of the `getIn` helper and ready to serve a cursor instance | ||
* purpose without having to write endlessly the same args over and over. | ||
* | ||
* @param {array} path - The path to get in the tree. | ||
* @return {object} - The result of the `getIn` helper. | ||
*/ | ||
_getIn(path) { | ||
return getIn( | ||
this.tree.data, | ||
path, | ||
this.tree._computedDataIndex, | ||
this.tree.options | ||
); | ||
} | ||
/** | ||
* Method returning the paths of the tree watched over by the cursor and that | ||
@@ -226,7 +234,3 @@ * should be taken into account when solving a potential update. | ||
if (type.dynamicPath(p)) | ||
p = getIn( | ||
this.tree.data, | ||
p, | ||
this._computedDataIndex | ||
).solvedPath; | ||
p = this._getIn(p).solvedPath; | ||
@@ -459,14 +463,34 @@ if (!p) | ||
_get(path=[]) { | ||
if (!type.path(path)) | ||
throw makeError('Baobab.Cursor.getters: invalid path.', {path}); | ||
if (!this.solvedPath) | ||
return {data: undefined, solvedPath: null}; | ||
return {data: undefined, solvedPath: null, exists: false}; | ||
return getIn( | ||
this.tree.data, | ||
this.solvedPath.concat(path), | ||
this.tree._computedDataIndex, | ||
this.tree.options | ||
); | ||
return this._getIn(this.solvedPath.concat(path)); | ||
} | ||
/** | ||
* Method used to check whether a certain path exists in the tree starting | ||
* from the current cursor. | ||
* | ||
* Arity (1): | ||
* @param {path} path - Path to check in the tree. | ||
* | ||
* Arity (2): | ||
* @param {..step} path - Path to check in the tree. | ||
* | ||
* @return {boolean} - Does the given path exists? | ||
*/ | ||
exists(path) { | ||
path = path || path === 0 ? path : []; | ||
if (arguments.length > 1) | ||
path = arrayFrom(arguments); | ||
return this._get(path).exists; | ||
} | ||
/** | ||
* Method used to get data from the tree. Will fire a `get` event from the | ||
@@ -480,3 +504,3 @@ * tree so that the user may sometimes react upon it to fetch data, for | ||
* Arity (2): | ||
* @param {..step} path - Path to get in the tree. | ||
* @param {..step} path - Path to get in the tree. | ||
* | ||
@@ -483,0 +507,0 @@ * @return {mixed} - Data at path. |
@@ -323,3 +323,4 @@ /** | ||
export function getIn(object, path, mask=null, opts={}) { | ||
path = path || []; | ||
if (!path) | ||
return notFoundObject; | ||
@@ -383,3 +384,3 @@ let solvedPath = [], | ||
return {data: c, solvedPath, exists: true}; | ||
return {data: c, solvedPath, exists: c !== undefined}; | ||
} | ||
@@ -386,0 +387,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
157501
3965