Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.
MIT License
3.15k stars 117 forks source link

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

Closed Nimelrian closed 7 years ago

Nimelrian commented 7 years ago

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.

Yomguithereal commented 7 years ago

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

Nimelrian commented 7 years ago

Pull request created and waiting for verification.

Nimelrian commented 7 years ago

Pull request merged, issue fixed.