From 948942528579d6da11f432c85ac58aaa1d1b44b4 Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 02:37:38 +0530 Subject: [PATCH 01/11] 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 } /** From 99fba7340fdbf370ab1c4e7dfa8c66b8bc75aaca Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 02:40:07 +0530 Subject: [PATCH 02/11] Update Readme for YArray chaining --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 886c12d0..f1286d10 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)
From 9f9309e58dae34e2be14da2ab28b9206e591db3b Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 02:51:43 +0530 Subject: [PATCH 03/11] Implement chaining for YMap functions --- src/types/YMap.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 } /** From b1d32bd256cfd0a3ac5c0535405eddbbea85836c Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 02:52:42 +0530 Subject: [PATCH 04/11] Update Readme for YMap chaining --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1286d10..5d37929e 100644 --- a/README.md +++ b/README.md @@ -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
From 77c73d5d2a040cdd85c186edd39996e2059c8648 Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 02:59:18 +0530 Subject: [PATCH 05/11] Implement chaining for YText functions --- src/types/YText.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 } /** From f60a915a74577ec63777ac851be3e148fb943c34 Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 03:10:56 +0530 Subject: [PATCH 06/11] Update Readme for YText chaining --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d37929e..e923948f 100644 --- a/README.md +++ b/README.md @@ -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
From 2d3d9f750646f2536461e258744400db97f35f00 Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 03:18:23 +0530 Subject: [PATCH 07/11] Implement chaining for YXmlFragment functions --- src/types/YXmlFragment.js | 4 ++++ 1 file changed, 4 insertions(+) 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 } /** From deefdfabc789b017e165ceeb0e2683c3d856d8fa Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 03:19:18 +0530 Subject: [PATCH 08/11] Update Readme for YXmlFragment chaining --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e923948f..5221e6cb 100644 --- a/README.md +++ b/README.md @@ -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)
From abd95a2ca1a2864d78c1eea095694c5ee021e95c Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 03:21:21 +0530 Subject: [PATCH 09/11] Implement chaining for YXmlElement functions --- src/types/YXmlElement.js | 4 ++++ 1 file changed, 4 insertions(+) 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 } /** From 3bba7a16d0f227d845be5a4a6eb256cd7ff842db Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 03:34:22 +0530 Subject: [PATCH 10/11] Update Readme for YXmlElement chaining --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5221e6cb..51b209f0 100644 --- a/README.md +++ b/README.md @@ -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
From 7307fda6a01b93672001902dc1d2ee46cf8622c7 Mon Sep 17 00:00:00 2001 From: Mansehej Date: Tue, 19 May 2020 04:20:09 +0530 Subject: [PATCH 11/11] Fix tests to work according to updated ymap return type --- tests/y-map.tests.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 => {