-
Notifications
You must be signed in to change notification settings - Fork 88
(DOCSP-26983): @realm/react-ify "Sets - React Native SDK" #2477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(DOCSP-26983): @realm/react-ify "Sets - React Native SDK" #2477
Conversation
Readability for Commit Hash: 2ddcf12 You can see any previous Readability scores (if they exist) by looking Flesch Reading Ease scores for changed documents:
The following table can be helpful in assessing the readability score of a document.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple small things but overall lgtm
@@ -31,8 +31,23 @@ To define a property type as a ``Realm Set``, specify the data type | |||
you want in the set, followed by ``<>``. For instance, for a set made of integer | |||
values, specify ``"int<>"``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values, specify ``"int<>"``. | |
values, specify ``'int<>'``. |
Example | ||
~~~~~~~ | ||
|
||
In the following example of a ``QueryCharacterInventory`` component we check the character's inventory size and if it has a specific item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the following example of a ``QueryCharacterInventory`` component we check the character's inventory size and if it has a specific item. | |
In the following example of a ``QueryCharacterInventory`` component, we check the character's inventory size and if it has a specific item. |
- Creates a `state variable <https://reactjs.org/docs/hooks-state.html>`__ called "inventory" that will hold the character's inventory items in order of insertion. | ||
- Retrieves the character by passing the ``Character`` class to the ``useQuery()`` hook and running the :js-sdk:`Collection.filtered() <Realm.Collection.html#filtered>` method on the result to filter for characters with the name matching the ``characterName`` prop. Then we set the variable ``character`` to the first matching result. | ||
- Creates a component method ``addInventoryItem()`` that performs a write transaction that adds an inventory item to the character's inventory by passing the ``inventoryItem`` state variable to the :js-sdk:`Realm.Set.add() <Realm.Set.html#add>` method. After the write transaction, the method adds the ``inventoryItem`` to the ``inventory`` array state variable. | ||
- Renders a ``TextInput`` that changes the ``inventoryItem`` state variable, and a ``Button`` that calls the ``addInventoryItem()`` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Renders a ``TextInput`` that changes the ``inventoryItem`` state variable, and a ``Button`` that calls the ``addInventoryItem()`` method. | |
- Renders a ``TextInput`` that changes the ``inventoryItem`` state variable, and renders a ``Button`` that calls the ``addInventoryItem()`` method. |
(same as earlier - could also remove the comma or "Renders a TextInput
... as well as a Button
...")
- Creates a `state variable <https://reactjs.org/docs/hooks-state.html>`__ called "inventoryItem" that represents the inventory item to remove from the inventory set. | ||
- Creates a component method ``removeInventoryItem`` that passes the ``inventoryItem`` state variable to the :js-sdk:`Realm.Set.delete() <Realm.Set.html#delete>` method to remove the item from the character's inventory. | ||
- Creates a component method ``removeAllInventory`` that calls the :js-sdk:`Realm.Set.clear() <Realm.Set.html#clear>` method to remove all items from the character's inventory. | ||
- Renders a ``TextInput`` that changes the ``inventoryItem`` state variable, and two ``Button``s that call the ``removeInventoryItem`` and ``removeAllInventory`` methods, respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Renders a ``TextInput`` that changes the ``inventoryItem`` state variable, and two ``Button``s that call the ``removeInventoryItem`` and ``removeAllInventory`` methods, respectively. | |
- Renders a ``TextInput`` that changes the ``inventoryItem`` state variable and two ``Button``s that call the ``removeInventoryItem`` and ``removeAllInventory`` methods, respectively. |
Also, you'll need to change how you refer to the plural Buttons
. The closing backticks aren't being recognized because of the s
, so the formatting is incorrectly applied to all of the following text: Button` `s that call the removeInventoryItem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, referring to them here as: two Button
components
|
||
.. literalinclude:: /examples/generated/node/data-types.snippet.make-array-with-insertion-order-from-set.js | ||
:language: javascript | ||
However, by default the order of the items in a set is not guaranteed. To |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, by default the order of the items in a set is not guaranteed. To | |
However, the order of the items in a set is not guaranteed by default. To |
Example | ||
~~~~~~~ | ||
|
||
In the following example of a ``TraverseCharacterInventory`` component a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the following example of a ``TraverseCharacterInventory`` component a | |
In the following example of a ``TraverseCharacterInventory`` component, a |
|
||
- Gets access to an opened realm instance by calling the ``useRealm()`` hook within the component. | ||
- Creates a `state variable <https://reactjs.org/docs/hooks-state.html>`__ called "inventoryItem" that represents the new inventory item to add to the inventory set. | ||
- Retrieves the character by passing the ``Character`` class to the ``useQuery()`` hook and running the :js-sdk:`Collection.filtered() <Realm.Collection.html#filtered>` method on the result to filter for characters with the name matching the ``characterName`` prop. Then we set the variable ``character`` to the first matching result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Retrieves the character by passing the ``Character`` class to the ``useQuery()`` hook and running the :js-sdk:`Collection.filtered() <Realm.Collection.html#filtered>` method on the result to filter for characters with the name matching the ``characterName`` prop. Then we set the variable ``character`` to the first matching result. | |
- Retrieves the character by passing the ``Character`` class to the ``useQuery()`` hook and running the :js-sdk:`Collection.filtered() <Realm.Collection.html#filtered>` method on the result to filter for characters with the name matching the ``characterName`` `prop <https://reactjs.org/docs/components-and-props.html>`__. Then we set the variable ``character`` to the first matching result. |
Co-authored-by: cbullinger <[email protected]>
Co-authored-by: cbullinger <[email protected]>
Co-authored-by: cbullinger <[email protected]>
## Pull Request Info ### Jira - https://jira.mongodb.org/browse/DOCSP-26983 ### Staged Changes - [Sets - React Native SDK](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26983-realmset/sdk/react-native/realm-database/schemas/sets/) ### Reminder Checklist If your PR modifies the docs, you might need to also update some corresponding pages. Check if completed or N/A. - [N/A] Create Jira ticket for corresponding docs-app-services update(s), if any - [N/A] Checked/updated Admin API - [N/A] Checked/updated CLI reference ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md) Co-authored-by: Mohammad Hunan Chughtai <[email protected]> Co-authored-by: cbullinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool examples here. I have some suggestions to clean things up a bit.
properties: { | ||
_id: 'objectId', | ||
name: 'string', | ||
levelsCompleted: 'int<>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated in other PRs, I think it's worthwhile to show both the shorthand and object notation for defining schema properties:
levelsCompleted: {
type: "set",
objectType: "int"
}
|
||
Check if a Set has Specific Items and Check the Size of a Set | ||
------------------------------------------------------------- | ||
You may want to check for information about your set, such as the set's size or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to check for information about your set, such as the set's size or | |
You may want to check for information about your ``Set``, such as the ``Set``'s size or |
I think it would be good to keep refering to Set similarly throughout the document, so that it's clear we are talking about the Set
data type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be checked throughout the entire document. It's not just here
|
||
Check if a Set has Specific Items | ||
--------------------------------- | ||
To determine if a set contains a particular value, pass the value to the ``<Realm.Set>.has()`` method. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set.has
is refered to differently twice in this paragraph. This should be unified.
## Pull Request Info ### Jira - https://jira.mongodb.org/browse/DOCSP-26983 ### Staged Changes - [Sets - React Native SDK](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26983-realmset/sdk/react-native/realm-database/schemas/sets/) ### Reminder Checklist If your PR modifies the docs, you might need to also update some corresponding pages. Check if completed or N/A. - [N/A] Create Jira ticket for corresponding docs-app-services update(s), if any - [N/A] Checked/updated Admin API - [N/A] Checked/updated CLI reference ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md) Co-authored-by: Mohammad Hunan Chughtai <[email protected]> Co-authored-by: cbullinger <[email protected]>
Pull Request Info
Jira
Staged Changes
Reminder Checklist
If your PR modifies the docs, you might need to also update some corresponding
pages. Check if completed or N/A.
Review Guidelines
REVIEWING.md