diff --git a/README.md b/README.md
index 606cbcd9..427d3e67 100644
--- a/README.md
+++ b/README.md
@@ -242,17 +242,17 @@ necessary.
const yarray = new Y.Array()
- insert(index:number, content:Array<object|boolean|Array|string|number|Uint8Array|Y.Type>)
+ insert(index:number, content:Array<object|boolean|Array|string|number|Uint8Array|Y.Type>):Y.Array
-
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
position 0.
- push(Array<Object|boolean|Array|string|number|Uint8Array|Y.Type>)
+ push(Array<Object|boolean|Array|string|number|Uint8Array|Y.Type>):Y.Array
- unshift(Array<Object|boolean|Array|string|number|Uint8Array|Y.Type>)
+ unshift(Array<Object|boolean|Array|string|number|Uint8Array|Y.Type>):Y.Array
- delete(index:number, length:number)
+ delete(index:number, length:number):Y.Array
get(index:number)
@@ -313,9 +313,9 @@ or any of its children.
get(key:string):object|boolean|string|number|Uint8Array|Y.Type
- set(key:string, value:object|boolean|string|number|Uint8Array|Y.Type)
+ set(key:string, value:object|boolean|string|number|Uint8Array|Y.Type):Y.Map
- delete(key:string)
+ delete(key:string):Y.Map
has(key:string):boolean
@@ -388,14 +388,14 @@ YTextEvents compute changes as deltas.
const ytext = new Y.Text()
- insert(index:number, content:string, [formattingAttributes:Object<string,string>])
+ insert(index:number, content:string, [formattingAttributes:Object<string,string>]):Y.Text
-
Insert a string at index and assign formatting attributes to it.
ytext.insert(0, 'bold text', { bold: true })
- delete(index:number, length:number)
+ delete(index:number, length:number):Y.Text
- format(index:number, length:number, formattingAttributes:Object<string,string>)
+ format(index:number, length:number, formattingAttributes:Object<string,string>):Y.Text
- Assign formatting attributes to a range in the text
applyDelta(delta, opts:Object<string,any>)
-
@@ -446,9 +446,9 @@ or any of its children.
const yxml = new Y.XmlFragment()
- insert(index:number, content:Array<Y.XmlElement|Y.XmlText>)
+ insert(index:number, content:Array<Y.XmlElement|Y.XmlText>):Y.XmlFragment
- delete(index:number, length:number)
+ delete(index:number, length:number):Y.XmlFragment
get(index:number)
@@ -497,17 +497,17 @@ content and be actually XML compliant.
const yxml = new Y.XmlElement()
- insert(index:number, content:Array<Y.XmlElement|Y.XmlText>)
+ insert(index:number, content:Array<Y.XmlElement|Y.XmlText>):Y.XmlElement
- delete(index:number, length:number)
+ delete(index:number, length:number):Y.XmlElement
get(index:number)
length:number
- setAttribute(attributeName:string, attributeValue:string)
+ setAttribute(attributeName:string, attributeValue:string):Y.XmlElement
- removeAttribute(attributeName:string)
+ removeAttribute(attributeName:string):Y.XmlElement
getAttribute(attributeName:string):string
diff --git a/src/types/YArray.js b/src/types/YArray.js
index 02ad42f0..db5a7a56 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
}
/**
diff --git a/src/types/YMap.js b/src/types/YMap.js
index 47df69ad..933b69d2 100644
--- a/src/types/YMap.js
+++ b/src/types/YMap.js
@@ -180,6 +180,7 @@ export class YMap extends AbstractType {
* Remove a specified element from this YMap.
*
* @param {string} key The key of the element to remove.
+ * @return {YMap} Instance of the YMap.
*/
delete (key) {
if (this.doc !== null) {
@@ -189,6 +190,7 @@ export class YMap extends AbstractType {
} else {
/** @type {Map} */ (this._prelimContent).delete(key)
}
+ return this
}
/**
@@ -196,6 +198,7 @@ export class YMap extends AbstractType {
*
* @param {string} key The key of the element to add to this YMap
* @param {T} value The value of the element to add
+ * @return {YMap} Instance of the YMap
*/
set (key, value) {
if (this.doc !== null) {
@@ -205,7 +208,7 @@ export class YMap extends AbstractType {
} else {
/** @type {Map} */ (this._prelimContent).set(key, value)
}
- return value
+ return this
}
/**
diff --git a/src/types/YText.js b/src/types/YText.js
index 81e87a0a..0e93e622 100644
--- a/src/types/YText.js
+++ b/src/types/YText.js
@@ -997,11 +997,12 @@ export class YText extends AbstractType {
* @param {TextAttributes} [attributes] Optionally define some formatting
* information to apply on the inserted
* Text.
+ * @return {YText} Instance of the YText.
* @public
*/
insert (index, text, attributes) {
if (text.length <= 0) {
- return
+ return this
}
const y = this.doc
if (y !== null) {
@@ -1017,6 +1018,7 @@ export class YText extends AbstractType {
} else {
/** @type {Array} */ (this._pending).push(() => this.insert(index, text, attributes))
}
+ return this
}
/**
@@ -1049,12 +1051,13 @@ export class YText extends AbstractType {
*
* @param {number} index Index at which to start deleting.
* @param {number} length The number of characters to remove. Defaults to 1.
+ * @return {YText} Instance of the YText.
*
* @public
*/
delete (index, length) {
if (length === 0) {
- return
+ return this
}
const y = this.doc
if (y !== null) {
@@ -1065,6 +1068,7 @@ export class YText extends AbstractType {
} else {
/** @type {Array} */ (this._pending).push(() => this.delete(index, length))
}
+ return this
}
/**
@@ -1074,12 +1078,13 @@ export class YText extends AbstractType {
* @param {number} length The amount of characters to assign properties to.
* @param {TextAttributes} attributes Attribute information to apply on the
* text.
+ * @return {YText} Instance of the YText.
*
* @public
*/
format (index, length, attributes) {
if (length === 0) {
- return
+ return this
}
const y = this.doc
if (y !== null) {
@@ -1093,6 +1098,7 @@ export class YText extends AbstractType {
} else {
/** @type {Array} */ (this._pending).push(() => this.format(index, length, attributes))
}
+ return this
}
/**
diff --git a/src/types/YXmlElement.js b/src/types/YXmlElement.js
index c16e7abb..c9599de8 100644
--- a/src/types/YXmlElement.js
+++ b/src/types/YXmlElement.js
@@ -89,6 +89,7 @@ export class YXmlElement extends YXmlFragment {
* Removes an attribute from this YXmlElement.
*
* @param {String} attributeName The attribute name that is to be removed.
+ * @return {YXmlElement} Instance of the YXmlElement.
*
* @public
*/
@@ -100,6 +101,7 @@ export class YXmlElement extends YXmlFragment {
} else {
/** @type {Map} */ (this._prelimAttrs).delete(attributeName)
}
+ return this
}
/**
@@ -107,6 +109,7 @@ export class YXmlElement extends YXmlFragment {
*
* @param {String} attributeName The attribute name that is to be set.
* @param {String} attributeValue The attribute value that is to be set.
+ * @return {YXmlElement} Instance of the YXmlElement.
*
* @public
*/
@@ -118,6 +121,7 @@ export class YXmlElement extends YXmlFragment {
} else {
/** @type {Map} */ (this._prelimAttrs).set(attributeName, attributeValue)
}
+ return this
}
/**
diff --git a/src/types/YXmlFragment.js b/src/types/YXmlFragment.js
index 36bdb2d9..d8611bb0 100644
--- a/src/types/YXmlFragment.js
+++ b/src/types/YXmlFragment.js
@@ -281,6 +281,7 @@ export class YXmlFragment extends AbstractType {
*
* @param {number} index The index to insert content at
* @param {Array} content The array of content
+ * @return {YXmlFragment} Instance of the YXmlFragment.
*/
insert (index, content) {
if (this.doc !== null) {
@@ -291,6 +292,7 @@ export class YXmlFragment extends AbstractType {
// @ts-ignore _prelimContent is defined because this is not yet integrated
this._prelimContent.splice(index, 0, ...content)
}
+ return this
}
/**
@@ -298,6 +300,7 @@ export class YXmlFragment extends AbstractType {
*
* @param {number} index Index at which to start deleting elements
* @param {number} [length=1] The number of elements to remove. Defaults to 1.
+ * @return {YXmlFragment} Instance of the YXmlFragment.
*/
delete (index, length = 1) {
if (this.doc !== null) {
@@ -308,6 +311,7 @@ export class YXmlFragment extends AbstractType {
// @ts-ignore _prelimContent is defined because this is not yet integrated
this._prelimContent.splice(index, length)
}
+ return this
}
/**
diff --git a/tests/y-map.tests.js b/tests/y-map.tests.js
index 2c3d128a..403dcc78 100644
--- a/tests/y-map.tests.js
+++ b/tests/y-map.tests.js
@@ -109,7 +109,8 @@ export const testGetAndSetOfMapProperty = tc => {
*/
export const testYmapSetsYmap = tc => {
const { users, map0 } = init(tc, { users: 2 })
- const map = map0.set('Map', new Y.Map())
+ const map = new Y.Map()
+ map0.set('Map', map)
t.assert(map0.get('Map') === map)
map.set('one', 1)
t.compare(map.get('one'), 1)
@@ -121,7 +122,8 @@ export const testYmapSetsYmap = tc => {
*/
export const testYmapSetsYarray = tc => {
const { users, map0 } = init(tc, { users: 2 })
- const array = map0.set('Array', new Y.Array())
+ const array = new Y.Array()
+ map0.set('Array', array)
t.assert(array === map0.get('Array'))
array.insert(0, [1, 2, 3])
// @ts-ignore
@@ -234,7 +236,8 @@ export const testGetAndSetAndDeleteOfMapPropertyWithThreeConflicts = tc => {
*/
export const testObserveDeepProperties = tc => {
const { testConnector, users, map1, map2, map3 } = init(tc, { users: 4 })
- const _map1 = map1.set('map', new Y.Map())
+ const _map1 = new Y.Map()
+ map1.set('map', _map1)
let calls = 0
let dmapid
map1.observeDeep(events => {