From e59b6aec4271267b582bc920cdb99facf334c21b Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 02:56:37 -0400 Subject: [PATCH 01/26] added set examples + bluehawked --- examples/node/Examples/data-types.js | 79 +++++++++++++++++++ .../data-types.codeblock.add-items-to-set.js | 4 + ...-types.codeblock.check-if-set-has-items.js | 5 ++ .../data-types.codeblock.check-set-size.js | 3 + ...data-types.codeblock.create-set-objects.js | 15 ++++ ...data-types.codeblock.define-set-objects.js | 10 +++ ...pes.codeblock.remove-all-items-from-set.js | 4 + 7 files changed, 120 insertions(+) create mode 100644 source/examples/generated/node/data-types.codeblock.add-items-to-set.js create mode 100644 source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js create mode 100644 source/examples/generated/node/data-types.codeblock.check-set-size.js create mode 100644 source/examples/generated/node/data-types.codeblock.create-set-objects.js create mode 100644 source/examples/generated/node/data-types.codeblock.define-set-objects.js create mode 100644 source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 285ee631f6..9ec6a7e7fe 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -299,4 +299,83 @@ describe("Node.js Data Types", () => { // close the realm realm.close(); }); + test("should work with the Set data type", async () => { + // :code-block-start: define-set-objects + const characterSchema = { + name: "Character", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + levelsCompleted: "int<>", + inventory: "string<>", + }, + }; + // :code-block-end: + const realm = await Realm.open({ + schema: [characterSchema], + }); + + // :code-block-start: create-set-objects + let link, hunter; + realm.write(() => { + link = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "Link", + inventory: ["elixir", "compass", "glowing shield"], + levelsCompleted: [4, 9], + }); + hunter = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "Hunter", + inventory: ["estus flask", "gloves", "rune"], + levelsCompleted: [1, 2, 5, 24], + }); + }); + // :code-block-end: + + expect(link.inventory.has("elixir")).toBe(true); + expect(hunter.inventory.has("gloves")).toBe(true); + + // :code-block-start: add-items-to-set + realm.write(() => { + link.inventory.add("hammer"); + link.levelsCompleted.add(32); + }); + // :code-block-end: + + expect(link.inventory.size).toBe(4); + expect(link.levelsCompleted.size).toBe(3); + + // :code-block-start: check-if-set-has-items + // check if the hunter has completed level 3 by calling the `set.has()` method + const hunterHasCompletedLevelThree = hunter.levelsCompleted.has(3); + console.log( + `Is level three completed by the hunter: ${hunterHasCompletedLevelThree}` + ); + // :code-block-end: + expect(hunterHasCompletedLevelThree).toBe(false); + + // :code-block-start: remove-all-items-from-set + realm.write(() => { + // clear all data from the items slot of the hunter by calling `set.clear()` in a write transaction + hunter.inventory.clear(); + }); + // :code-block-end: + + // :code-block-start: check-set-size + // check how many items the hunter has in his inventory through the `set.size` property + const hunterInventorySize = hunter.inventory.size; + console.log(`The hunter has ${hunterInventorySize} inventory items`); + // :code-block-end: + expect(hunter.inventory.size).toBe(0); + + // delete the object specifically created in this test to keep tests idempotent + realm.write(() => { + realm.delete(link); + realm.delete(hunter); + }); + // close the realm + realm.close(); + }); }); diff --git a/source/examples/generated/node/data-types.codeblock.add-items-to-set.js b/source/examples/generated/node/data-types.codeblock.add-items-to-set.js new file mode 100644 index 0000000000..b925b154b1 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.add-items-to-set.js @@ -0,0 +1,4 @@ +realm.write(() => { + link.inventory.add("hammer"); + link.levelsCompleted.add(32); +}); diff --git a/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js new file mode 100644 index 0000000000..ffb87a4404 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js @@ -0,0 +1,5 @@ +// check if the hunter has completed level 3 by calling the `set.has()` method +const hunterHasCompletedLevelThree = hunter.levelsCompleted.has(3); +console.log( + `Is level three completed by the hunter: ${hunterHasCompletedLevelThree}` +); diff --git a/source/examples/generated/node/data-types.codeblock.check-set-size.js b/source/examples/generated/node/data-types.codeblock.check-set-size.js new file mode 100644 index 0000000000..07412edee2 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.check-set-size.js @@ -0,0 +1,3 @@ +// check how many items the hunter has in his inventory through the `set.size` property +const hunterInventorySize = hunter.inventory.size; +console.log(`The hunter has ${hunterInventorySize} inventory items`); diff --git a/source/examples/generated/node/data-types.codeblock.create-set-objects.js b/source/examples/generated/node/data-types.codeblock.create-set-objects.js new file mode 100644 index 0000000000..c4259456c9 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.create-set-objects.js @@ -0,0 +1,15 @@ +let link, hunter; +realm.write(() => { + link = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "Link", + inventory: ["elixir", "compass", "glowing shield"], + levelsCompleted: [4, 9], + }); + hunter = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "Hunter", + inventory: ["estus flask", "gloves", "rune"], + levelsCompleted: [1, 2, 5, 24], + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.define-set-objects.js b/source/examples/generated/node/data-types.codeblock.define-set-objects.js new file mode 100644 index 0000000000..e0bb37bf64 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.define-set-objects.js @@ -0,0 +1,10 @@ +const characterSchema = { + name: "Character", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + levelsCompleted: "int<>", + inventory: "string<>", + }, +}; diff --git a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js new file mode 100644 index 0000000000..f84f54492d --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js @@ -0,0 +1,4 @@ +realm.write(() => { + // clear all data from the items slot of the hunter by calling `set.clear()` in a write transaction + hunter.inventory.clear(); +}); From b8be1d8a82bfe5f0e1e6a02731b77b136d04f277 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 03:07:41 -0400 Subject: [PATCH 02/26] literal included set exampkes --- source/sdk/node/data-types/sets.txt | 45 ++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 5dc7b5b845..007d10a62f 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -15,4 +15,47 @@ Sets - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- + +.. _node-define-set-objects: + +Realm Object Models +------------------- +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js + :language: javascript + +.. _node-create-set-objects: + +Create an Object With a Set +--------------------------- +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js + :language: javascript + + +.. _node-add-items-to-set: + +Add Items to a Set +------------------ +.. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js + :language: javascript + +.. _node-check-if-set-has-items: + +Check if a Set has Specific Items +--------------------------------- +.. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js + :language: javascript + +.. _node-check-set-size: + +Check the Size of a Set +----------------------- +.. literalinclude:: /examples/generated/node/data-types.codeblock.check-set-size.js + :language: javascript + +.. _node-remove-all-items-from-set: + +Remove all Items from a Set +--------------------------- +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js + :language: javascript From 10ef9dbad94acecab161ede5a7193ea119155d39 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 03:14:40 -0400 Subject: [PATCH 03/26] added delete one set item example --- examples/node/Examples/data-types.js | 9 +++++++++ ...data-types.codeblock.remove-specific-item-from-set.js | 5 +++++ source/sdk/node/data-types/sets.txt | 8 ++++++++ 3 files changed, 22 insertions(+) create mode 100644 source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 9ec6a7e7fe..531c6b1dd8 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -356,6 +356,15 @@ describe("Node.js Data Types", () => { // :code-block-end: expect(hunterHasCompletedLevelThree).toBe(false); + // :code-block-start: remove-specific-item-from-set + realm.write(() => { + // remove the compass from link's inventory by calling `set.delete()` within a write transaction + link.inventory.delete("compass"); + }); + + // :code-block-end: + expect(link.inventory.has("compass")).toBe(false); + // :code-block-start: remove-all-items-from-set realm.write(() => { // clear all data from the items slot of the hunter by calling `set.clear()` in a write transaction diff --git a/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js new file mode 100644 index 0000000000..a2386aa150 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js @@ -0,0 +1,5 @@ +realm.write(() => { + // remove the compass from link's inventory by calling `set.delete()` within a write transaction + link.inventory.delete("compass"); +}); + diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 007d10a62f..8d442f3123 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -53,6 +53,14 @@ Check the Size of a Set .. literalinclude:: /examples/generated/node/data-types.codeblock.check-set-size.js :language: javascript +.. _node-remove-specific-item-from-set: + +Remove an Item from a Set +------------------------- +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js + :language: javascript + + .. _node-remove-all-items-from-set: Remove all Items from a Set From ad8f25ebde9f213ca65de1320adea8727e8eb594 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 03:16:14 -0400 Subject: [PATCH 04/26] fix typo --- examples/node/Examples/data-types.js | 2 +- .../node/data-types.codeblock.remove-all-items-from-set.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 531c6b1dd8..73cd4495d7 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -367,7 +367,7 @@ describe("Node.js Data Types", () => { // :code-block-start: remove-all-items-from-set realm.write(() => { - // clear all data from the items slot of the hunter by calling `set.clear()` in a write transaction + // clear all data from the inventory slot of the hunter by calling `set.clear()` in a write transaction hunter.inventory.clear(); }); // :code-block-end: diff --git a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js index f84f54492d..2c3eeb32de 100644 --- a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js +++ b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js @@ -1,4 +1,4 @@ realm.write(() => { - // clear all data from the items slot of the hunter by calling `set.clear()` in a write transaction + // clear all data from the inventory slot of the hunter by calling `set.clear()` in a write transaction hunter.inventory.clear(); }); From b5322f9257e3a0d4b8b03ed634df739851323a52 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 09:27:51 -0400 Subject: [PATCH 05/26] added descriptions to set --- source/sdk/node/data-types/sets.txt | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 8d442f3123..d4a6aa307b 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -16,11 +16,28 @@ Sets - Node.js SDK Overview -------- - +A {+service-short+} set is a special object that allows you to store a +collection of unique values. {+service-short+} sets work similarly to JavaScript +:mdn:`Sets ` except they must be a single +type, and can only be modified within a write-transaction. + +.. note:: {+service-short+} Sets Do Not Guarantee Traversal Order + + When using a ``forEach()`` loop or other :mdn:`iteration methods + ` to iterate + through a loop, {+service-short+} sets may be in a different order than + originally written to. If you require an ordered version of your set, you + must implement that ordering yourself, for instance by creating an array of + the set's values in the insertion order. + .. _node-define-set-objects: Realm Object Models ------------------- +To define a property's values as a {+service-short+} set, specify the data type +followed by a less than and equal sign. For instance, for a set made of integer +values, specify ``"int<>"``. + .. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js :language: javascript @@ -28,6 +45,11 @@ Realm Object Models Create an Object With a Set --------------------------- +To create an object with a property that value is of the set data type, create a +{+service-short+} object within a write transaction. When defining your +{+service-short+} object, specify your set property's value as an array of +initial values. + .. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js :language: javascript @@ -36,6 +58,8 @@ Create an Object With a Set Add Items to a Set ------------------ +To add items to a set, pass the new value to the ``set.add()`` method within a write transaction. + .. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js :language: javascript @@ -43,6 +67,9 @@ Add Items to a Set Check if a Set has Specific Items --------------------------------- +To find out if a set has a particular value, pass the value to the ``set.has()`` method. The +``set.has()`` method will return true if the set contains the value specified. + .. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js :language: javascript @@ -50,6 +77,8 @@ Check if a Set has Specific Items Check the Size of a Set ----------------------- +To discover how many items are in a set, you can check the set's ``size`` property. + .. literalinclude:: /examples/generated/node/data-types.codeblock.check-set-size.js :language: javascript @@ -57,6 +86,8 @@ Check the Size of a Set Remove an Item from a Set ------------------------- +To remove a specific value from a set, pass the value to the ``set.delete()`` method within a write transaction. + .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js :language: javascript @@ -65,5 +96,7 @@ Remove an Item from a Set Remove all Items from a Set --------------------------- +To clear the set, run the ``set.clear()`` method within a write transaction. + .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js :language: javascript From 5ddbb5f3cfb2e729ff3ecfbc2a7021bed16a1444 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 09:38:31 -0400 Subject: [PATCH 06/26] fix grammar --- source/sdk/node/data-types/sets.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index d4a6aa307b..434bc6ac0a 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -18,8 +18,8 @@ Overview -------- A {+service-short+} set is a special object that allows you to store a collection of unique values. {+service-short+} sets work similarly to JavaScript -:mdn:`Sets ` except they must be a single -type, and can only be modified within a write-transaction. +:mdn:`Sets `, except they must be a single +type and can only be modified within a write-transaction. .. note:: {+service-short+} Sets Do Not Guarantee Traversal Order @@ -27,7 +27,7 @@ type, and can only be modified within a write-transaction. ` to iterate through a loop, {+service-short+} sets may be in a different order than originally written to. If you require an ordered version of your set, you - must implement that ordering yourself, for instance by creating an array of + must implement that order yourself. You can do this by creating an array of the set's values in the insertion order. .. _node-define-set-objects: From 62dae49a0ee6077d8eb8d0f898b85c967a2c78bb Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 16:13:55 -0400 Subject: [PATCH 07/26] changed link + hunter to generic names --- examples/node/Examples/data-types.js | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 73cd4495d7..366a4ce510 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -317,72 +317,72 @@ describe("Node.js Data Types", () => { }); // :code-block-start: create-set-objects - let link, hunter; + let playerOne, playerTwo; realm.write(() => { - link = realm.create("Character", { + playerOne = realm.create("Character", { _id: new BSON.ObjectId(), - name: "Link", + name: "PlayerOne", inventory: ["elixir", "compass", "glowing shield"], levelsCompleted: [4, 9], }); - hunter = realm.create("Character", { + playerTwo = realm.create("Character", { _id: new BSON.ObjectId(), - name: "Hunter", + name: "PlayerTwo", inventory: ["estus flask", "gloves", "rune"], levelsCompleted: [1, 2, 5, 24], }); }); // :code-block-end: - expect(link.inventory.has("elixir")).toBe(true); - expect(hunter.inventory.has("gloves")).toBe(true); + expect(playerOne.inventory.has("elixir")).toBe(true); + expect(playerTwo.inventory.has("gloves")).toBe(true); // :code-block-start: add-items-to-set realm.write(() => { - link.inventory.add("hammer"); - link.levelsCompleted.add(32); + playerOne.inventory.add("hammer"); + playerOne.levelsCompleted.add(32); }); // :code-block-end: - expect(link.inventory.size).toBe(4); - expect(link.levelsCompleted.size).toBe(3); + expect(playerOne.inventory.size).toBe(4); + expect(playerOne.levelsCompleted.size).toBe(3); // :code-block-start: check-if-set-has-items - // check if the hunter has completed level 3 by calling the `set.has()` method - const hunterHasCompletedLevelThree = hunter.levelsCompleted.has(3); + // check if the playerTwo has completed level 3 by calling the `set.has()` method + const playerTwoHasCompletedLevelThree = playerTwo.levelsCompleted.has(3); console.log( - `Is level three completed by the hunter: ${hunterHasCompletedLevelThree}` + `Is level three completed by the playerTwo: ${playerTwoHasCompletedLevelThree}` ); // :code-block-end: - expect(hunterHasCompletedLevelThree).toBe(false); + expect(playerTwoHasCompletedLevelThree).toBe(false); // :code-block-start: remove-specific-item-from-set realm.write(() => { - // remove the compass from link's inventory by calling `set.delete()` within a write transaction - link.inventory.delete("compass"); + // remove the compass from playerOne's inventory by calling `set.delete()` within a write transaction + playerOne.inventory.delete("compass"); }); // :code-block-end: - expect(link.inventory.has("compass")).toBe(false); + expect(playerOne.inventory.has("compass")).toBe(false); // :code-block-start: remove-all-items-from-set realm.write(() => { - // clear all data from the inventory slot of the hunter by calling `set.clear()` in a write transaction - hunter.inventory.clear(); + // clear all data from the inventory slot of the playerTwo by calling `set.clear()` in a write transaction + playerTwo.inventory.clear(); }); // :code-block-end: // :code-block-start: check-set-size - // check how many items the hunter has in his inventory through the `set.size` property - const hunterInventorySize = hunter.inventory.size; - console.log(`The hunter has ${hunterInventorySize} inventory items`); + // check how many items the playerTwo has in his inventory through the `set.size` property + const playerTwoInventorySize = playerTwo.inventory.size; + console.log(`The playerTwo has ${playerTwoInventorySize} inventory items`); // :code-block-end: - expect(hunter.inventory.size).toBe(0); + expect(playerTwo.inventory.size).toBe(0); // delete the object specifically created in this test to keep tests idempotent realm.write(() => { - realm.delete(link); - realm.delete(hunter); + realm.delete(playerOne); + realm.delete(playerTwo); }); // close the realm realm.close(); From 30304192a153ae1aa8196977c4d705145da5b6a1 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 16:19:11 -0400 Subject: [PATCH 08/26] added capitalization to clearly define Realm Set as a term --- source/sdk/node/data-types/sets.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 434bc6ac0a..666aa90abc 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -16,16 +16,16 @@ Sets - Node.js SDK Overview -------- -A {+service-short+} set is a special object that allows you to store a -collection of unique values. {+service-short+} sets work similarly to JavaScript +A ``{+service-short+} Set`` is a special object that allows you to store a +collection of unique values. ``{+service-short+} Sets`` work similarly to JavaScript :mdn:`Sets `, except they must be a single type and can only be modified within a write-transaction. -.. note:: {+service-short+} Sets Do Not Guarantee Traversal Order +.. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order When using a ``forEach()`` loop or other :mdn:`iteration methods ` to iterate - through a loop, {+service-short+} sets may be in a different order than + through a loop, ``{+service-short+} Sets`` may be in a different order than originally written to. If you require an ordered version of your set, you must implement that order yourself. You can do this by creating an array of the set's values in the insertion order. @@ -34,7 +34,7 @@ type and can only be modified within a write-transaction. Realm Object Models ------------------- -To define a property's values as a {+service-short+} set, specify the data type +To define a property's values as a ``{+service-short+} Set``, specify the data type followed by a less than and equal sign. For instance, for a set made of integer values, specify ``"int<>"``. From 179fdfc5212a5fbef6500db17af595e654242d14 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 16:26:07 -0400 Subject: [PATCH 09/26] fix wording + formatting" --- source/sdk/node/data-types/sets.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 666aa90abc..8390b48f89 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -17,9 +17,10 @@ Sets - Node.js SDK Overview -------- A ``{+service-short+} Set`` is a special object that allows you to store a -collection of unique values. ``{+service-short+} Sets`` work similarly to JavaScript -:mdn:`Sets `, except they must be a single -type and can only be modified within a write-transaction. +collection of unique values. ``{+service-short+} Sets`` work similarly to +JavaScript :mdn:`Sets `, except +they must contain a single type and can only be modified within a write +transaction. .. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order From e5baab51dbe39d4b378d593b3e5db37007f8ccd9 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 16:37:20 -0400 Subject: [PATCH 10/26] clarified wording --- source/sdk/node/data-types/sets.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 8390b48f89..f3cdc690a1 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -28,7 +28,7 @@ transaction. ` to iterate through a loop, ``{+service-short+} Sets`` may be in a different order than originally written to. If you require an ordered version of your set, you - must implement that order yourself. You can do this by creating an array of + must implement that ordering yourself. You can do this by creating an array of the set's values in the insertion order. .. _node-define-set-objects: @@ -59,7 +59,7 @@ initial values. Add Items to a Set ------------------ -To add items to a set, pass the new value to the ``set.add()`` method within a write transaction. +To add an item to a set, pass the new value to the ``.add()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js :language: javascript @@ -68,7 +68,7 @@ To add items to a set, pass the new value to the ``set.add()`` method within a w Check if a Set has Specific Items --------------------------------- -To find out if a set has a particular value, pass the value to the ``set.has()`` method. The +To find out if a set contains a particular value, pass the value to the ``.has()`` method. The ``set.has()`` method will return true if the set contains the value specified. .. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js @@ -87,7 +87,7 @@ To discover how many items are in a set, you can check the set's ``size`` proper Remove an Item from a Set ------------------------- -To remove a specific value from a set, pass the value to the ``set.delete()`` method within a write transaction. +To remove a specific value from a set, pass the value to the ``.delete()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js :language: javascript @@ -97,7 +97,7 @@ To remove a specific value from a set, pass the value to the ``set.delete()`` me Remove all Items from a Set --------------------------- -To clear the set, run the ``set.clear()`` method within a write transaction. +To clear the set, run the ``.clear()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js :language: javascript From 1c4a3a3782e487ff68ce75fc94d949188a06fa2d Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 16:39:52 -0400 Subject: [PATCH 11/26] fix literalincldue indentation --- source/sdk/node/data-types/sets.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index f3cdc690a1..5a97069f6a 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -40,7 +40,7 @@ followed by a less than and equal sign. For instance, for a set made of integer values, specify ``"int<>"``. .. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js - :language: javascript + :language: javascript .. _node-create-set-objects: @@ -52,7 +52,7 @@ To create an object with a property that value is of the set data type, create a initial values. .. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js - :language: javascript + :language: javascript .. _node-add-items-to-set: @@ -62,7 +62,7 @@ Add Items to a Set To add an item to a set, pass the new value to the ``.add()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js - :language: javascript + :language: javascript .. _node-check-if-set-has-items: @@ -72,7 +72,7 @@ To find out if a set contains a particular value, pass the value to the ``. ``set.has()`` method will return true if the set contains the value specified. .. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js - :language: javascript + :language: javascript .. _node-check-set-size: @@ -81,7 +81,7 @@ Check the Size of a Set To discover how many items are in a set, you can check the set's ``size`` property. .. literalinclude:: /examples/generated/node/data-types.codeblock.check-set-size.js - :language: javascript + :language: javascript .. _node-remove-specific-item-from-set: @@ -90,7 +90,7 @@ Remove an Item from a Set To remove a specific value from a set, pass the value to the ``.delete()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js - :language: javascript + :language: javascript .. _node-remove-all-items-from-set: @@ -100,4 +100,4 @@ Remove all Items from a Set To clear the set, run the ``.clear()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js - :language: javascript + :language: javascript From 4a469f3c5d601fa961c6abc877973d1293bbadf4 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 16:41:10 -0400 Subject: [PATCH 12/26] fix typo --- source/sdk/node/data-types/sets.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 5a97069f6a..97dd034a35 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -36,7 +36,7 @@ transaction. Realm Object Models ------------------- To define a property's values as a ``{+service-short+} Set``, specify the data type -followed by a less than and equal sign. For instance, for a set made of integer +followed by a less than and greater than sign. For instance, for a set made of integer values, specify ``"int<>"``. .. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js From 15fbdb8d70ec15cfe6cf6c052a1d7a8f113f498b Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 17:53:03 -0400 Subject: [PATCH 13/26] more wording fixes --- source/sdk/node/data-types/sets.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 97dd034a35..9837e45c08 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -24,12 +24,12 @@ transaction. .. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order - When using a ``forEach()`` loop or other :mdn:`iteration methods - ` to iterate - through a loop, ``{+service-short+} Sets`` may be in a different order than - originally written to. If you require an ordered version of your set, you - must implement that ordering yourself. You can do this by creating an array of - the set's values in the insertion order. + When using a ``forEach()`` loop or other :mdn:`iteration method + ` to traverse + the set in a loop, the content of the ``{+service-short+} Set`` may be in a + different order than originally written to. If you require an ordered version + of your set, you must implement that ordering yourself. You can do this by + creating an array of the set's values in the insertion order. .. _node-define-set-objects: @@ -68,7 +68,7 @@ To add an item to a set, pass the new value to the ``.add()`` method within Check if a Set has Specific Items --------------------------------- -To find out if a set contains a particular value, pass the value to the ``.has()`` method. The +To determine if a set contains a particular value, pass the value to the ``.has()`` method. The ``set.has()`` method will return true if the set contains the value specified. .. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js From 81c94ad9fda64d6045ec456cb8caf61448f62463 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 17:55:45 -0400 Subject: [PATCH 14/26] clean up realm object model for set wording --- source/sdk/node/data-types/sets.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 9837e45c08..dbce33cbbf 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -35,8 +35,8 @@ transaction. Realm Object Models ------------------- -To define a property's values as a ``{+service-short+} Set``, specify the data type -followed by a less than and greater than sign. For instance, for a set made of integer +To define a property type as a ``{+service-short+} Set``, specify the data type +you want in the set, followed by ``<>``. For instance, for a set made of integer values, specify ``"int<>"``. .. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js From 55f6e4f924193d6fe2a73780e80dff208c19beae Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 10:39:25 -0400 Subject: [PATCH 15/26] fix character names for examples --- .../node/data-types.codeblock.add-items-to-set.js | 4 ++-- .../data-types.codeblock.check-if-set-has-items.js | 6 +++--- .../node/data-types.codeblock.check-set-size.js | 6 +++--- .../node/data-types.codeblock.create-set-objects.js | 10 +++++----- .../data-types.codeblock.remove-all-items-from-set.js | 4 ++-- ...ta-types.codeblock.remove-specific-item-from-set.js | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/examples/generated/node/data-types.codeblock.add-items-to-set.js b/source/examples/generated/node/data-types.codeblock.add-items-to-set.js index b925b154b1..988cd8c26b 100644 --- a/source/examples/generated/node/data-types.codeblock.add-items-to-set.js +++ b/source/examples/generated/node/data-types.codeblock.add-items-to-set.js @@ -1,4 +1,4 @@ realm.write(() => { - link.inventory.add("hammer"); - link.levelsCompleted.add(32); + characterOne.inventory.add("hammer"); + characterOne.levelsCompleted.add(32); }); diff --git a/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js index ffb87a4404..6e2ae5921e 100644 --- a/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js +++ b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js @@ -1,5 +1,5 @@ -// check if the hunter has completed level 3 by calling the `set.has()` method -const hunterHasCompletedLevelThree = hunter.levelsCompleted.has(3); +// check if the characterTwo has completed level 3 by calling the `set.has()` method +const characterTwoHasCompletedLevelThree = characterTwo.levelsCompleted.has(3); console.log( - `Is level three completed by the hunter: ${hunterHasCompletedLevelThree}` + `Is level three completed by the characterTwo: ${characterTwoHasCompletedLevelThree}` ); diff --git a/source/examples/generated/node/data-types.codeblock.check-set-size.js b/source/examples/generated/node/data-types.codeblock.check-set-size.js index 07412edee2..dedb25e4c6 100644 --- a/source/examples/generated/node/data-types.codeblock.check-set-size.js +++ b/source/examples/generated/node/data-types.codeblock.check-set-size.js @@ -1,3 +1,3 @@ -// check how many items the hunter has in his inventory through the `set.size` property -const hunterInventorySize = hunter.inventory.size; -console.log(`The hunter has ${hunterInventorySize} inventory items`); +// check how many items the characterTwo has in his inventory through the `set.size` property +const characterTwoInventorySize = characterTwo.inventory.size; +console.log(`The characterTwo has ${characterTwoInventorySize} inventory items`); diff --git a/source/examples/generated/node/data-types.codeblock.create-set-objects.js b/source/examples/generated/node/data-types.codeblock.create-set-objects.js index c4259456c9..dd47653332 100644 --- a/source/examples/generated/node/data-types.codeblock.create-set-objects.js +++ b/source/examples/generated/node/data-types.codeblock.create-set-objects.js @@ -1,14 +1,14 @@ -let link, hunter; +let characterOne, characterTwo; realm.write(() => { - link = realm.create("Character", { + characterOne = realm.create("Character", { _id: new BSON.ObjectId(), - name: "Link", + name: "CharacterOne", inventory: ["elixir", "compass", "glowing shield"], levelsCompleted: [4, 9], }); - hunter = realm.create("Character", { + characterTwo = realm.create("Character", { _id: new BSON.ObjectId(), - name: "Hunter", + name: "CharacterTwo", inventory: ["estus flask", "gloves", "rune"], levelsCompleted: [1, 2, 5, 24], }); diff --git a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js index 2c3eeb32de..6abf904211 100644 --- a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js +++ b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js @@ -1,4 +1,4 @@ realm.write(() => { - // clear all data from the inventory slot of the hunter by calling `set.clear()` in a write transaction - hunter.inventory.clear(); + // clear all data from the inventory slot of the characterTwo by calling `set.clear()` in a write transaction + characterTwo.inventory.clear(); }); diff --git a/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js index a2386aa150..76dde2973f 100644 --- a/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js +++ b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js @@ -1,5 +1,5 @@ realm.write(() => { - // remove the compass from link's inventory by calling `set.delete()` within a write transaction - link.inventory.delete("compass"); + // remove the compass from characterOne's inventory by calling `set.delete()` within a write transaction + characterOne.inventory.delete("compass"); }); From dc7d0714885fcbbe56dc2e50d3da1a94a60cb413 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 10:55:17 -0400 Subject: [PATCH 16/26] clarified traversal order wording --- source/sdk/node/data-types/sets.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index dbce33cbbf..9552a3fe91 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -28,8 +28,12 @@ transaction. ` to traverse the set in a loop, the content of the ``{+service-short+} Set`` may be in a different order than originally written to. If you require an ordered version - of your set, you must implement that ordering yourself. You can do this by - creating an array of the set's values in the insertion order. + of your set, you must implement that ordering yourself.If you require an + ordered version of your set, you must implement that order yourself. You can + do this by creating an array from the set, using :mdn:`Array.from() + `, and updating that + array when the set has been modified through a :ref:`change listener + `. .. _node-define-set-objects: From c5561b741b59812d22ee4621cbf17e2fb1138a76 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 10:59:36 -0400 Subject: [PATCH 17/26] rst typo in --- source/sdk/node/data-types/sets.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 9552a3fe91..3cb1fed3d4 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -30,7 +30,7 @@ transaction. different order than originally written to. If you require an ordered version of your set, you must implement that ordering yourself.If you require an ordered version of your set, you must implement that order yourself. You can - do this by creating an array from the set, using :mdn:`Array.from() + do this by creating an array from the set, using :mdn:`Array.from(set) `, and updating that array when the set has been modified through a :ref:`change listener `. From 5312d697fd0d766e5cd5e04e0e277daa7b9ff43a Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 11:03:44 -0400 Subject: [PATCH 18/26] changed set to mySet --- source/sdk/node/data-types/sets.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 3cb1fed3d4..8a62c90053 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -30,7 +30,7 @@ transaction. different order than originally written to. If you require an ordered version of your set, you must implement that ordering yourself.If you require an ordered version of your set, you must implement that order yourself. You can - do this by creating an array from the set, using :mdn:`Array.from(set) + do this by creating an array from the set, using :mdn:`Array.from(mySet) `, and updating that array when the set has been modified through a :ref:`change listener `. From ac8a4ec5eb517e966c38b2519ae998e8cf9d6357 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 11:26:42 -0400 Subject: [PATCH 19/26] fix overview wording --- source/sdk/node/data-types/sets.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 8a62c90053..f03815bf20 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -17,10 +17,9 @@ Sets - Node.js SDK Overview -------- A ``{+service-short+} Set`` is a special object that allows you to store a -collection of unique values. ``{+service-short+} Sets`` work similarly to -JavaScript :mdn:`Sets `, except -they must contain a single type and can only be modified within a write -transaction. +collection of unique values. ``{+service-short+} Sets`` are based on JavaScript +:mdn:`Sets `, but can only contain +values of a single type and can only be modified within a write transaction. .. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order From cad7aec37139124f049f40d95917c8897370e667 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 12:09:52 -0400 Subject: [PATCH 20/26] updated overview to be more clear on differences between array --- source/sdk/node/data-types/sets.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index f03815bf20..b032c3e13f 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -20,6 +20,10 @@ A ``{+service-short+} Set`` is a special object that allows you to store a collection of unique values. ``{+service-short+} Sets`` are based on JavaScript :mdn:`Sets `, but can only contain values of a single type and can only be modified within a write transaction. +Sets allow you to perform math operations such as finding the union, +intersection, or difference between two sets. To learn more about performing +these operations, see the mdn docs for :mdn:`Implementing basic set operations +` .. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order From 545a3c0f5de1afb95c9875feb0f7839b15b05b04 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 12:34:33 -0400 Subject: [PATCH 21/26] updated create wording --- source/sdk/node/data-types/sets.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index b032c3e13f..6f7be80242 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -22,7 +22,7 @@ collection of unique values. ``{+service-short+} Sets`` are based on JavaScript values of a single type and can only be modified within a write transaction. Sets allow you to perform math operations such as finding the union, intersection, or difference between two sets. To learn more about performing -these operations, see the mdn docs for :mdn:`Implementing basic set operations +these operations, see the MDN docs for :mdn:`Implementing basic set operations ` .. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order @@ -53,10 +53,10 @@ values, specify ``"int<>"``. Create an Object With a Set --------------------------- -To create an object with a property that value is of the set data type, create a -{+service-short+} object within a write transaction. When defining your -{+service-short+} object, specify your set property's value as an array of -initial values. +To create an object with a ``{+service-short+} Set`` property, you must create +the object within a write transaction. When defining your {+service-short+} +object, initialize the ``{+service-short+} Set`` by passing an empty array or an +array with your initial values. .. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js :language: javascript From a2e838766ff0a49ba386700971108be25a8730a0 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 08:47:12 -0400 Subject: [PATCH 22/26] Update source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js Co-authored-by: Kenneth Geisshirt --- .../node/data-types.codeblock.remove-all-items-from-set.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js index 6abf904211..4e4a5d0792 100644 --- a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js +++ b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js @@ -1,4 +1,4 @@ realm.write(() => { - // clear all data from the inventory slot of the characterTwo by calling `set.clear()` in a write transaction + // clear all data from the inventory slot of the characterTwo by calling `Realm.Set.clear()` in a write transaction characterTwo.inventory.clear(); }); From 2e37543e114459848a3b7dbc89c05e8c1fc7c03b Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 08:47:21 -0400 Subject: [PATCH 23/26] Update source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js Co-authored-by: Kenneth Geisshirt --- .../node/data-types.codeblock.remove-specific-item-from-set.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js index 76dde2973f..cec2514e5b 100644 --- a/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js +++ b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js @@ -1,5 +1,4 @@ realm.write(() => { - // remove the compass from characterOne's inventory by calling `set.delete()` within a write transaction + // remove the compass from characterOne's inventory by calling `Realm.Set.delete()` within a write transaction characterOne.inventory.delete("compass"); }); - From d6f993d4a111fd46a0a83f6913d4f52074620d8e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 08:47:33 -0400 Subject: [PATCH 24/26] Update source/sdk/node/data-types/sets.txt Co-authored-by: Kenneth Geisshirt --- source/sdk/node/data-types/sets.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 6f7be80242..dfb1c150b8 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -31,7 +31,7 @@ these operations, see the MDN docs for :mdn:`Implementing basic set operations ` to traverse the set in a loop, the content of the ``{+service-short+} Set`` may be in a different order than originally written to. If you require an ordered version - of your set, you must implement that ordering yourself.If you require an + of your set, you must implement that ordering yourself. If you require an ordered version of your set, you must implement that order yourself. You can do this by creating an array from the set, using :mdn:`Array.from(mySet) `, and updating that From 5d8338d57e820d6cfb85a1fa6b444d737bf8c9fd Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:04:46 -0400 Subject: [PATCH 25/26] fix grammar + wording + changed Set to Realm.Set in js snippets --- .../data-types.codeblock.check-if-set-has-items.js | 2 +- .../node/data-types.codeblock.check-set-size.js | 2 +- source/sdk/node/data-types/sets.txt | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js index 6e2ae5921e..0e09ea622d 100644 --- a/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js +++ b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js @@ -1,4 +1,4 @@ -// check if the characterTwo has completed level 3 by calling the `set.has()` method +// check if the characterTwo has completed level 3 by calling the `Realm.Set.has()` method const characterTwoHasCompletedLevelThree = characterTwo.levelsCompleted.has(3); console.log( `Is level three completed by the characterTwo: ${characterTwoHasCompletedLevelThree}` diff --git a/source/examples/generated/node/data-types.codeblock.check-set-size.js b/source/examples/generated/node/data-types.codeblock.check-set-size.js index dedb25e4c6..d864c79192 100644 --- a/source/examples/generated/node/data-types.codeblock.check-set-size.js +++ b/source/examples/generated/node/data-types.codeblock.check-set-size.js @@ -1,3 +1,3 @@ -// check how many items the characterTwo has in his inventory through the `set.size` property +// check how many items the characterTwo has in his inventory through the `Realm.Set.size` property const characterTwoInventorySize = characterTwo.inventory.size; console.log(`The characterTwo has ${characterTwoInventorySize} inventory items`); diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 175a9b59e8..b4dcacacd4 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -18,16 +18,16 @@ Overview -------- A ``{+service-short+} Set`` is a special object that allows you to store a collection of unique values. ``{+service-short+} Sets`` are based on JavaScript -:mdn:`Sets `, but can only contain +:mdn:`sets `, but can only contain values of a single type and can only be modified within a write transaction. Sets allow you to perform math operations such as finding the union, intersection, or difference between two sets. To learn more about performing these operations, see the MDN docs for :mdn:`Implementing basic set operations -` +`. .. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order - When using a ``forEach()`` loop or other :mdn:`iteration method + When using a ``forEach()`` loop or alternative :mdn:`iteration method ` to traverse the set in a loop, the content of the ``{+service-short+} Set`` may be in a different order than originally written to. If you require an ordered version @@ -67,7 +67,7 @@ array with your initial values. Add Items to a Set ------------------ -To add an item to a set, pass the new value to the ``.add()`` method within a write transaction. +To add an item to a set, pass the new value to the ``.add()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js :language: javascript @@ -76,7 +76,7 @@ To add an item to a set, pass the new value to the ``.add()`` method within Check if a Set has Specific Items --------------------------------- -To determine if a set contains a particular value, pass the value to the ``.has()`` method. The +To determine if a set contains a particular value, pass the value to the ``.has()`` method. The ``set.has()`` method will return true if the set contains the value specified. .. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js @@ -95,7 +95,7 @@ To discover how many items are in a set, you can check the set's ``size`` proper Remove an Item from a Set ------------------------- -To remove a specific value from a set, pass the value to the ``.delete()`` method within a write transaction. +To remove a specific value from a set, pass the value to the ``.delete()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js :language: javascript @@ -105,7 +105,7 @@ To remove a specific value from a set, pass the value to the ``.delete()`` Remove all Items from a Set --------------------------- -To clear the set, run the ``.clear()`` method within a write transaction. +To clear the set, run the ``.clear()`` method within a write transaction. .. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js :language: javascript From b5edd4b4e862d44d2cfebe72b724ea1180a1d60e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:09:57 -0400 Subject: [PATCH 26/26] Fix woridng --- source/sdk/node/data-types/sets.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index b4dcacacd4..17ab6b948c 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -35,9 +35,10 @@ these operations, see the MDN docs for :mdn:`Implementing basic set operations ordered version of your set, you must implement that order yourself. You can do this by creating an array from the set, using :mdn:`Array.from(mySet) ` or the :mdn:`spread - operator `. Then you can - react to changes to that array when the set has been modified by using a - :ref:`change listener `. + operator `. You can keep + that array updated by using a :ref:`change listener ` + to react to changes to the set. + .. _node-define-set-objects: