diff --git a/README.md b/README.md index 886c12d0..51b209f0 100644 --- a/README.md +++ b/README.md @@ -221,17 +221,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)
@@ -292,9 +292,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
@@ -367,14 +367,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)
See Quill Delta
@@ -421,9 +421,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)
@@ -472,17 +472,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 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 } /** diff --git a/src/types/YMap.js b/src/types/YMap.js index f0f06630..8f35168b 100644 --- a/src/types/YMap.js +++ b/src/types/YMap.js @@ -161,6 +161,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) { @@ -170,6 +171,7 @@ export class YMap extends AbstractType { } else { /** @type {Map} */ (this._prelimContent).delete(key) } + return this } /** @@ -177,6 +179,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) { @@ -186,7 +189,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 e02b2514..a1fa1eb3 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -989,11 +989,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) { @@ -1009,6 +1010,7 @@ export class YText extends AbstractType { } else { /** @type {Array} */ (this._pending).push(() => this.insert(index, text, attributes)) } + return this } /** @@ -1041,12 +1043,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) { @@ -1057,6 +1060,7 @@ export class YText extends AbstractType { } else { /** @type {Array} */ (this._pending).push(() => this.delete(index, length)) } + return this } /** @@ -1066,12 +1070,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) { @@ -1085,6 +1090,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 f8876be7..15ead6bb 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 cb38b0ee..af1e32af 100644 --- a/tests/y-map.tests.js +++ b/tests/y-map.tests.js @@ -80,7 +80,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) @@ -92,7 +93,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 @@ -191,7 +193,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 => {