Comparing version 2.1.2 to 2.2.0
# Changelog | ||
## v2.2.0 (provisional) | ||
## v2.2.0 | ||
* Cursors are now ES6 iterables ([@kirjs](https://github.com/kirjs)). | ||
* Dropping the `.babelrc` file from the npm build. | ||
@@ -7,0 +8,0 @@ ## v2.1.2 |
@@ -589,3 +589,3 @@ /** | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.1.2' | ||
value: '2.2.0' | ||
}); | ||
@@ -592,0 +592,0 @@ |
@@ -188,14 +188,7 @@ /** | ||
/** | ||
* Setter Methods | ||
* --------------- | ||
* Method used to allow iterating over cursors containing list-type data. | ||
* | ||
* Those methods are dynamically assigned to the class for DRY reasons. | ||
*/ | ||
/** | ||
* Function creating a setter method for the Cursor class. | ||
* e.g. for(let i of cursor) { ... } | ||
* | ||
* @param {string} name - the method's name. | ||
* @param {function} [typeChecker] - a function checking that the given value is | ||
* valid for the given operation. | ||
* @returns {object} - Each item sequentially. | ||
*/ | ||
@@ -426,35 +419,2 @@ | ||
/** | ||
* Method used to allow iterating over cursors containing list-type data. | ||
* | ||
* e.g. for(let i of cursor) { ... } | ||
* | ||
* @returns {object} - Each item sequentially. | ||
// */ | ||
// [Symbol.iterator]() { | ||
// const array = this._get().data; | ||
// if (!type.array(array)) | ||
// throw Error('baobab.Cursor.@@iterate: cannot iterate a non-list type.'); | ||
// let i = 0; | ||
// const cursor = this, | ||
// length = array.length; | ||
// return { | ||
// next: function() { | ||
// if (i < length) { | ||
// return { | ||
// value: cursor.select(i++) | ||
// }; | ||
// } | ||
// return { | ||
// done: true | ||
// }; | ||
// } | ||
// }; | ||
// } | ||
/** | ||
* Getter Methods | ||
@@ -773,2 +733,43 @@ * --------------- | ||
exports['default'] = Cursor; | ||
if (typeof Symbol === 'function' && typeof Symbol.iterator !== 'undefined') { | ||
Cursor.prototype[Symbol.iterator] = function () { | ||
var array = this._get().data; | ||
if (!_type2['default'].array(array)) throw Error('baobab.Cursor.@@iterate: cannot iterate a non-list type.'); | ||
var i = 0; | ||
var cursor = this, | ||
length = array.length; | ||
return { | ||
next: function next() { | ||
if (i < length) { | ||
return { | ||
value: cursor.select(i++) | ||
}; | ||
} | ||
return { | ||
done: true | ||
}; | ||
} | ||
}; | ||
}; | ||
} | ||
/** | ||
* Setter Methods | ||
* --------------- | ||
* | ||
* Those methods are dynamically assigned to the class for DRY reasons. | ||
*/ | ||
/** | ||
* Function creating a setter method for the Cursor class. | ||
* | ||
* @param {string} name - the method's name. | ||
* @param {function} [typeChecker] - a function checking that the given value is | ||
* valid for the given operation. | ||
*/ | ||
function makeSetter(name, typeChecker) { | ||
@@ -775,0 +776,0 @@ |
{ | ||
"name": "baobab", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "JavaScript persistent data tree with cursors.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/baobab.js", |
@@ -564,3 +564,3 @@ /** | ||
Object.defineProperty(Baobab, 'version', { | ||
value: '2.1.2' | ||
value: '2.2.0' | ||
}); | ||
@@ -567,0 +567,0 @@ |
@@ -389,35 +389,2 @@ /** | ||
/** | ||
* Method used to allow iterating over cursors containing list-type data. | ||
* | ||
* e.g. for(let i of cursor) { ... } | ||
* | ||
* @returns {object} - Each item sequentially. | ||
// */ | ||
// [Symbol.iterator]() { | ||
// const array = this._get().data; | ||
// if (!type.array(array)) | ||
// throw Error('baobab.Cursor.@@iterate: cannot iterate a non-list type.'); | ||
// let i = 0; | ||
// const cursor = this, | ||
// length = array.length; | ||
// return { | ||
// next: function() { | ||
// if (i < length) { | ||
// return { | ||
// value: cursor.select(i++) | ||
// }; | ||
// } | ||
// return { | ||
// done: true | ||
// }; | ||
// } | ||
// }; | ||
// } | ||
/** | ||
* Getter Methods | ||
@@ -721,2 +688,37 @@ * --------------- | ||
/** | ||
* Method used to allow iterating over cursors containing list-type data. | ||
* | ||
* e.g. for(let i of cursor) { ... } | ||
* | ||
* @returns {object} - Each item sequentially. | ||
*/ | ||
if (typeof Symbol === 'function' && typeof Symbol.iterator !== 'undefined') { | ||
Cursor.prototype[Symbol.iterator] = function() { | ||
const array = this._get().data; | ||
if (!type.array(array)) | ||
throw Error('baobab.Cursor.@@iterate: cannot iterate a non-list type.'); | ||
let i = 0; | ||
const cursor = this, | ||
length = array.length; | ||
return { | ||
next: function() { | ||
if (i < length) { | ||
return { | ||
value: cursor.select(i++) | ||
}; | ||
} | ||
return { | ||
done: true | ||
}; | ||
} | ||
}; | ||
}; | ||
} | ||
/** | ||
* Setter Methods | ||
@@ -723,0 +725,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
4710
188680
19