Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tree/cursor.splice does not conform with the specification as of ES6 (ECMAScript 2015)

Nimelrian opened this issue · comments

As of ECMAScript 2015, when the deleteCount argument of Array.prototype.splice is undefined, it is automatically set to the difference of the array's length and the start value. In other words, everything from (and including) the start argument is removed from the array.

As such, the following should work:

const Baobab = require('baobab');

const tree = new Baobab({
	array: [0, 1, 2, 3]
}, {asynchronous: false});
const arrayCursor = tree.select('array');

console.log(arrayCursor.get()); // [0, 1, 2, 3]
arrayCursor.splice([2]);
console.log(arrayCursor.get()); // [0, 1]

Instead, Baobab throws an error because only one argument has been provided to the splice call.

Thanks for noticing it @Nimelrian. I'll gladly accept a PR fixing this one.

Pull request created and waiting for verification.

Pull request merged, issue fixed.