Skip to content

(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

Conversation

mohammadhunan-dev
Copy link
Contributor

@mohammadhunan-dev mohammadhunan-dev commented Jan 10, 2023

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.

  • [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

@github-actions
Copy link

github-actions bot commented Jan 10, 2023

Readability for Commit Hash: 2ddcf12

You can see any previous Readability scores (if they exist) by looking
at the comment's history.

Flesch Reading Ease scores for changed documents:

  • source/sdk/react-native/realm-database/schemas/sets: 47.59

The following table can be helpful in assessing the readability score of a document.

Score Difficulty
90-100 Very Easy
80-89 Easy
70-79 Fairly Easy
60-69 Medium
50-59 Fairly Hard
30-49 Hard
0-29 Very Hard

@mohammadhunan-dev mohammadhunan-dev changed the base branch from master to realm-react-guidance January 11, 2023 16:50
@mohammadhunan-dev mohammadhunan-dev changed the title WIP - Docsp 26983 realmset WIP - (DOCSP-26983): @realm/react-ify "Sets - React Native SDK" Jan 11, 2023
@mohammadhunan-dev mohammadhunan-dev changed the title WIP - (DOCSP-26983): @realm/react-ify "Sets - React Native SDK" (DOCSP-26983): @realm/react-ify "Sets - React Native SDK" Jan 13, 2023
Copy link
Collaborator

@cbullinger cbullinger left a 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<>"``.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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

Copy link
Contributor Author

@mohammadhunan-dev mohammadhunan-dev Jan 18, 2023

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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.

@mohammadhunan-dev mohammadhunan-dev merged commit eb10407 into mongodb:realm-react-guidance Jan 18, 2023
mongodben pushed a commit that referenced this pull request Feb 10, 2023
## 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]>
Copy link
Collaborator

@takameyer takameyer left a 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<>',
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Collaborator

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
Copy link
Collaborator

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.

mongodben pushed a commit that referenced this pull request Mar 21, 2023
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants