From 821df429312a6edd96587c66155b90dc8fc9060a Mon Sep 17 00:00:00 2001 From: Mansehej Date: Wed, 13 May 2020 02:31:53 +0530 Subject: [PATCH] Add unshift function in Y.Array unshift(Array inserts parameters to the beginning of the yarray --- README.md | 2 ++ src/types/YArray.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 5ebdcd95..f6503646 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ 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) 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. *