Comparing version 2.0.0 to 2.0.1
# Changelog | ||
## v2.0.1 | ||
* Fixing monkeys' laziness (**@Zache**). | ||
* Fixing issues related to the root cursor. | ||
* Fixing `get` event edge cases. | ||
## v2.0.0 | ||
@@ -4,0 +10,0 @@ |
@@ -156,3 +156,4 @@ /** | ||
// Properties | ||
this.root = this.select(); | ||
this.root = new _cursor2['default'](this, [], '/'); | ||
delete this.root.release; | ||
@@ -408,3 +409,3 @@ // Does the user want an immutable tree? | ||
// Stashing previous data if this is the frame's first update | ||
if (!this._transaction.length) this._previousData = this.get(); | ||
if (!this._transaction.length) this._previousData = this._data; | ||
@@ -517,2 +518,4 @@ // Applying the operation | ||
delete this.root; | ||
delete this._data; | ||
@@ -583,3 +586,3 @@ delete this._previousData; | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.0.0' | ||
value: '2.0.1' | ||
}); | ||
@@ -586,0 +589,0 @@ |
@@ -275,3 +275,3 @@ /** | ||
value: function root() { | ||
return this.tree.root; | ||
return this.tree.select(); | ||
} | ||
@@ -278,0 +278,0 @@ |
@@ -284,2 +284,4 @@ /** | ||
for (k in o) { | ||
if (_type2['default'].lazyGetter(o, k)) continue; | ||
p = o[k]; | ||
@@ -286,0 +288,0 @@ |
@@ -202,2 +202,4 @@ /** | ||
lazyGetter.isLazyGetter = true; | ||
this.tree._data = (0, _update3['default'])(this.tree._data, this.path, { type: 'monkey', value: lazyGetter }, this.tree.options).data; | ||
@@ -204,0 +206,0 @@ |
@@ -181,2 +181,15 @@ /** | ||
/** | ||
* Check if the given object property is a lazy getter used by a monkey. | ||
* | ||
* @param {mixed} o - The target object. | ||
* @param {string} propertyKey - The property to test. | ||
* @return {boolean} | ||
*/ | ||
type.lazyGetter = function (o, propertyKey) { | ||
var descriptor = Object.getOwnPropertyDescriptor(o, propertyKey); | ||
return descriptor && descriptor.get && descriptor.get.isLazyGetter === true; | ||
}; | ||
/** | ||
* Returns the type of the given monkey definition or `null` if invalid. | ||
@@ -183,0 +196,0 @@ * |
@@ -22,2 +22,4 @@ /** | ||
var _monkey = require('./monkey'); | ||
var _helpers = require('./helpers'); | ||
@@ -77,3 +79,13 @@ | ||
p[s] = opts.persistent ? (0, _helpers.shallowClone)(value) : value; | ||
if (opts.persistent) { | ||
p[s] = (0, _helpers.shallowClone)(value); | ||
} else if (value instanceof _monkey.MonkeyDefinition) { | ||
Object.defineProperty(p, s, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} else { | ||
p[s] = value; | ||
} | ||
} | ||
@@ -85,3 +97,7 @@ | ||
else if (operationType === 'monkey') { | ||
Object.defineProperty(p, s, { get: value, enumerable: true }); | ||
Object.defineProperty(p, s, { | ||
get: value, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
@@ -183,2 +199,5 @@ | ||
// If we are updating a dynamic node, we need not return the affected node | ||
if (_type2['default'].lazyGetter(p, s)) return { data: dummy.root }; | ||
// Returning new data object | ||
@@ -185,0 +204,0 @@ return { data: dummy.root, node: p[s] }; |
{ | ||
"name": "baobab", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/baobab.js", |
@@ -759,2 +759,15 @@ [![Build Status](https://travis-ci.org/Yomguithereal/baobab.svg)](https://travis-ci.org/Yomguithereal/baobab) | ||
*Mapping cursors over a list node* | ||
```js | ||
var tree = new Baobab({list: [1, 2, 3]}); | ||
tree.select('list').map(function(cursor, i) { | ||
console.log(cursor.get()); | ||
}); | ||
>>> 1 | ||
>>> 2 | ||
>>> 3 | ||
``` | ||
*Getting information about the cursor's location in the tree* | ||
@@ -761,0 +774,0 @@ |
@@ -118,3 +118,4 @@ /** | ||
// Properties | ||
this.root = this.select(); | ||
this.root = new Cursor(this, [], '/'); | ||
delete this.root.release; | ||
@@ -395,3 +396,3 @@ // Does the user want an immutable tree? | ||
if (!this._transaction.length) | ||
this._previousData = this.get(); | ||
this._previousData = this._data; | ||
@@ -509,2 +510,4 @@ // Applying the operation | ||
delete this.root; | ||
delete this._data; | ||
@@ -572,3 +575,3 @@ delete this._previousData; | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.0.0' | ||
value: '2.0.1' | ||
}); | ||
@@ -575,0 +578,0 @@ |
@@ -237,3 +237,3 @@ /** | ||
root() { | ||
return this.tree.root; | ||
return this.tree.select(); | ||
} | ||
@@ -240,0 +240,0 @@ |
@@ -258,2 +258,5 @@ /** | ||
for (k in o) { | ||
if (type.lazyGetter(o, k)) | ||
continue; | ||
p = o[k]; | ||
@@ -260,0 +263,0 @@ |
@@ -186,2 +186,4 @@ /** | ||
lazyGetter.isLazyGetter = true; | ||
this.tree._data = update( | ||
@@ -188,0 +190,0 @@ this.tree._data, |
@@ -178,2 +178,17 @@ /** | ||
/** | ||
* Check if the given object property is a lazy getter used by a monkey. | ||
* | ||
* @param {mixed} o - The target object. | ||
* @param {string} propertyKey - The property to test. | ||
* @return {boolean} | ||
*/ | ||
type.lazyGetter = function(o, propertyKey) { | ||
const descriptor = Object.getOwnPropertyDescriptor(o, propertyKey); | ||
return descriptor && | ||
descriptor.get && | ||
descriptor.get.isLazyGetter === true; | ||
}; | ||
/** | ||
* Returns the type of the given monkey definition or `null` if invalid. | ||
@@ -180,0 +195,0 @@ * |
@@ -8,2 +8,3 @@ /** | ||
import type from './type'; | ||
import {MonkeyDefinition} from './monkey'; | ||
import { | ||
@@ -74,3 +75,15 @@ freeze, | ||
p[s] = opts.persistent ? shallowClone(value) : value; | ||
if (opts.persistent) { | ||
p[s] = shallowClone(value); | ||
} | ||
else if (value instanceof MonkeyDefinition) { | ||
Object.defineProperty(p, s, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
else { | ||
p[s] = value; | ||
} | ||
} | ||
@@ -82,3 +95,7 @@ | ||
else if (operationType === 'monkey') { | ||
Object.defineProperty(p, s, {get: value, enumerable: true}); | ||
Object.defineProperty(p, s, { | ||
get: value, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
@@ -235,4 +252,8 @@ | ||
// If we are updating a dynamic node, we need not return the affected node | ||
if (type.lazyGetter(p, s)) | ||
return {data: dummy.root}; | ||
// Returning new data object | ||
return {data: dummy.root, node: p[s]}; | ||
} |
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
181655
4553
968