Y.Array insert operations return new length

Y.Array functions
- insert
- push
- unshift

Return updated Y.Array length
This commit is contained in:
Mansehej 2020-05-13 03:07:07 +05:30
parent 821df42931
commit ee264dbaa2

View File

@ -101,6 +101,7 @@ export class YArray extends AbstractType {
* *
* @param {number} index The index to insert content at. * @param {number} index The index to insert content at.
* @param {Array<T>} content The array of content * @param {Array<T>} content The array of content
* @return {number} The upated YArray length
*/ */
insert (index, content) { insert (index, content) {
if (this.doc !== null) { if (this.doc !== null) {
@ -110,24 +111,27 @@ export class YArray extends AbstractType {
} else { } else {
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content) /** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
} }
return this.length
} }
/** /**
* Appends content to this YArray. * Appends content to this YArray.
* *
* @param {Array<T>} content Array of content to append. * @param {Array<T>} content Array of content to append.
* @return {number} The upated YArray length
*/ */
push (content) { push (content) {
this.insert(this.length, content) return this.insert(this.length, content)
} }
/** /**
* Preppends content to this YArray. * Preppends content to this YArray.
* *
* @param {Array<T>} content Array of content to preppend. * @param {Array<T>} content Array of content to preppend.
* @return {number} The upated YArray length
*/ */
unshift (content) { unshift (content) {
this.insert(0, content) return this.insert(0, content)
} }
/** /**