From 8bb52a485adf578eb6e2e183631d20fcdf997c7b Mon Sep 17 00:00:00 2001 From: Mansehej Date: Sat, 16 May 2020 02:36:43 +0530 Subject: [PATCH 1/2] Implement unshift to y-arrays --- src/types/YArray.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/types/YArray.js b/src/types/YArray.js index 58334df3..171eec8b 100644 --- a/src/types/YArray.js +++ b/src/types/YArray.js @@ -121,6 +121,15 @@ export class YArray extends AbstractType { this.insert(this.length, content) } + /** + * Preppends content to this YArray. + * + * @param {Array} content Array of content to preppend. + */ + unshift (content) { + this.insert(0, content) + } + /** * Deletes elements starting from an index. * From 4407f70052ee2264067001863ec9720fe530588c Mon Sep 17 00:00:00 2001 From: Mansehej Date: Sat, 16 May 2020 02:39:37 +0530 Subject: [PATCH 2/2] Update ReadMe for y-array unshift --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 16a61ef1..886c12d0 100644 --- a/README.md +++ b/README.md @@ -224,11 +224,13 @@ necessary. insert(index:number, content:Array<object|boolean|Array|string|number|Uint8Array|Y.Type>)
Insert content at index. Note that content is an array of elements. -I.e. array.insert(0, [1] splices the list and inserts 1 at +I.e. array.insert(0, [1]) splices the list and inserts 1 at position 0.
push(Array<Object|boolean|Array|string|number|Uint8Array|Y.Type>)
+ unshift(Array<Object|boolean|Array|string|number|Uint8Array|Y.Type>) +
delete(index:number, length:number)
get(index:number)