From 948942528579d6da11f432c85ac58aaa1d1b44b4 Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 02:37:38 +0530 Subject: [PATCH] Implement chaining for YArray functions --- src/types/YArray.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/types/YArray.js b/src/types/YArray.js index 171eec8b..072cadcc 100644 --- a/src/types/YArray.js +++ b/src/types/YArray.js @@ -101,6 +101,7 @@ export class YArray extends AbstractType { * * @param {number} index The index to insert content at. * @param {Array} content The array of content + * @return {YArray} Instance of the YArray */ insert (index, content) { if (this.doc !== null) { @@ -110,24 +111,27 @@ export class YArray extends AbstractType { } else { /** @type {Array} */ (this._prelimContent).splice(index, 0, ...content) } + return this } /** * Appends content to this YArray. * * @param {Array} content Array of content to append. + * @return {YArray} Instance of the YArray */ push (content) { - this.insert(this.length, content) + return this.insert(this.length, content) } /** * Preppends content to this YArray. * * @param {Array} content Array of content to preppend. + * @return {YArray} Instance of the YArray */ unshift (content) { - this.insert(0, content) + return this.insert(0, content) } /** @@ -135,6 +139,7 @@ export class YArray extends AbstractType { * * @param {number} index Index at which to start deleting elements * @param {number} length The number of elements to remove. Defaults to 1. + * @return {YArray} Instance of the YArray */ delete (index, length = 1) { if (this.doc !== null) { @@ -144,6 +149,7 @@ export class YArray extends AbstractType { } else { /** @type {Array} */ (this._prelimContent).splice(index, length) } + return this } /**