Skip to content

(DOCSP-26995) Reframe RN SDK open and close realm page #2529

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

Merged
merged 19 commits into from
Jan 31, 2023

Conversation

krollins-mdb
Copy link
Collaborator

@krollins-mdb krollins-mdb commented Jan 27, 2023

Pull Request Info

The Open and Close a Realm page needed a nearly complete overhaul because these concepts are very different with @realm/react.

I plan to re-evaluate the "Key Concept" section after we've finished the current Realm React epic.

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.

  • Create Jira ticket for corresponding docs-app-services update(s), if any
  • Checked/updated Admin API
  • Checked/updated CLI reference

Review Guidelines

REVIEWING.md

Animal wearing a hat

@krollins-mdb krollins-mdb changed the base branch from master to realm-react-guidance January 27, 2023 19:46
@github-actions
Copy link

github-actions bot commented Jan 27, 2023

Readability for Commit Hash: 1726539

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: 39.53
  • source/sdk/react-native/realm-database: -118.88
  • source/sdk/react-native/realm-database/bundle: 68.16
  • source/sdk/react-native/realm-database/configure-a-realm: 73.37
  • source/sdk/react-native/realm-database/encrypt: 55.34
  • source/sdk/react-native/realm-database/overview: 52.6

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

@krollins-mdb krollins-mdb marked this pull request as ready for review January 30, 2023 14:42
@@ -0,0 +1,20 @@
// :snippet-start: create-realm-context
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this file Models/index.js, not just Models.js?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it's the entry point for the directory and we can import like this:
import {RealmContext} from '../Models';

We could specify Models.js, but we use the index.js pattern in our demo apps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because it's the entry point for the directory and we can import like this:
import {RealmContext} from '../Models';

you could also achieve this with the following:

// Models.js

const RealmContext = someObject;

export RealmContext;

i'd rec not using the index.js file. to my knowledge, you usually only have an index file if there are other files in the directory that you want to export.


for example this pattern would make more sense if you had the following structure:

Models
|__ index.js
|__ Model1.js
|__ Model2.js

and then you wanted to export both Model1 and Model2 from Models, so the import would look like:

// someOtherFile.js
import {Model1, Model2} from './Models';

Copy link
Collaborator

@mongodben mongodben Jan 31, 2023

Choose a reason for hiding this comment

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

also now that i think more about it, it doesn't necessarily make sense to export realmContext from a file/directory called 'Models'. The configuration. contains more than the models/schema. also other stuff like in memory, encrypted ,etc.

perhaps rename the file RealmConfig.js?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, yeah. That makes a lot of sense. I've renamed to RealmConfig.js and moved it to the root of the __tests__ directory. RealmConfig.js should make this much easier to understand. Thanks for helping me think this through!

.. literalinclude:: /examples/generated/react-native/js/configure-realm-sync.test.snippet.configure-realm-sync.jsx
:language: javascript

Open more than one realm
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
Open more than one realm
Open Multiple Realms

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agh. This title casing on headings. I'll get it eventually. Old habits die hard.

I think I'm going to go with "Open One or More Realms" though. Because you might want to open just two. And two is not multiple.

Copy link
Collaborator

Choose a reason for hiding this comment

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

in that case, what about 'More than One' like you originally had it?

since you already talk about just the 'one realm' case above

Comment on lines 48 to 56
Enable Flexible Sync
~~~~~~~~~~~~~~~~~~~~

To use a Flexible Sync realm, you must nest ``<RealmProvider>`` within ``<AppProvider>``
and ``<UserProvider>``. This ensures your client has access to your App Services App
and that a user with permissions exists to access your realm data.

.. literalinclude:: /examples/generated/react-native/js/configure-realm-sync.test.snippet.configure-realm-sync.jsx
:language: javascript
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this section should probably be removed. to really get going w device sync, you need some more context, like app creation on the backend, enable flexible sync, etc.

this probably needs to be a different page. see flutter and swift sdks for example.

while it's def important to mention opening a synced realm on this page, i think it'd suffice to point to the 'open a synced realm' on this page. looks like there's already a ticket for @realm/reactifing that page, DOCSP-27009/).

to borrow some text for this section, you can see what's on the flutter page.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that makes a lot of sense. Thanks for pointing this out.

Comment on lines 13 to 24
The ``@realm/react`` library uses `React Context objects <https://reactjs.org/docs/context.html>`__
to create and configure realms. You can access realms with React hooks.

``@realm/react`` automatically opens and closes realms for you. To manage how it
does so, you need to pass props to the ``@realm/react`` Context Providers:

- ``<AppProvider>``
- ``<UserProvider>``
- ``<RealmProvider>``

For Flexible Sync realms, you need all three Providers, nested in the order above.
For local-only realms, you only need ``<RealmProvider>``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we can consolidate these paragraphs a fair bit. first, i think this page and the intro for it should focus much more on only local realms. and with that focus, i think the flow of the info could be more streamlined to something like:

Suggested change
The ``@realm/react`` library uses `React Context objects <https://reactjs.org/docs/context.html>`__
to create and configure realms. You can access realms with React hooks.
``@realm/react`` automatically opens and closes realms for you. To manage how it
does so, you need to pass props to the ``@realm/react`` Context Providers:
- ``<AppProvider>``
- ``<UserProvider>``
- ``<RealmProvider>``
For Flexible Sync realms, you need all three Providers, nested in the order above.
For local-only realms, you only need ``<RealmProvider>``.
The ``@realm/react`` library exposes realms throughout your application with `React Context objects <https://reactjs.org/docs/context.html>`__ and Provider components. You can access realms with React hooks.
To open a local realm, create a Context with the realm's configuration. The Context exports a `RealmProvider` component that exposes a realm with the configuration passed to the Context. All child components of the `RealmProvider` can access the realm using hooks.
To learn how to open a realm using Device Sync, refer to :ref:`Open a Synced Realm <TODO: add relevant ref>`.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@mongodben mongodben left a comment

Choose a reason for hiding this comment

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

great start! some higher level comments about documenting opening synced realm and nits throughout.

didn't focus much on code review in this pass since there might be non-trivial changes to what's included here. will give that a more thorough review once we're more settled on the copy.

Comment on lines 49 to 67
Open a Synced Realm
~~~~~~~~~~~~~~~~~~~

To open a realm that synchronizes data with Atlas using Device Sync,
refer to :ref:`Open a Synced Realm <react-native-open-a-synced-realm>`.

Open an In-Memory Realm
~~~~~~~~~~~~~~~~~~~~~~~

To create a realm that runs entirely in memory without being written to a file,
add ``inMemory: true`` to your :js-sdk:`Realm.Configuration
<Realm.html#~Configuration>` object:

.. literalinclude:: /examples/generated/react-native/ts/index.snippet.in-memory-realm.ts
:language: javascript
:emphasize-lines: 3

In-memory realms may use disk space if memory is running low, but files created
by an in-memory realm are deleted when you close the realm.
Copy link
Collaborator

Choose a reason for hiding this comment

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

rather than these 2 sections being under 'Configure a Realm with RealmProvider', i think it'd make more sense for these to be subsections of the 'Create a Context Object with createRealmContext' section since they're just about creating that context

:language: javascript
:caption: Models/index.js

Configure a Realm with ``<RealmProvider>``
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
Configure a Realm with ``<RealmProvider>``
Expose a Realm with ``<RealmProvider>``

not sure if 'configure' is the right word here since you're not actually making and config here. maybe 'expose' better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. The config happens in the previous section. I've updated locally. Will be in my next commit.

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.

Looks great. One heads up, I do have a PR which will allow one to use a default Context like so:

import {RealmProvider} from '@realm/react';

const AppWrapper = () => {
  return (
    <RealmProvider schema={[Item]} inMemory={true}>
      <App/>
    </RealmProvider>
  )
};

This would make the createRealmContext an advanced use case when a user wants to use more than one Realm.

Copy link
Collaborator

@mongodben mongodben left a comment

Choose a reason for hiding this comment

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

nice improvements! back to you w some smaller items throughout.

@krollins-mdb
Copy link
Collaborator Author

@takameyer, thank you! That's good to know about. I've created a Jira ticket to refactor this page when the new pattern has been released.

@@ -0,0 +1,27 @@
// :snippet-start: create-realm-context
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitish: could you put this in the ts/realm-database directory?

imo looks a little funky/confusing that when you import it in the code examples in the docs, the import statement goes up a few directories. ex https://github.com/mongodb/docs-realm/pull/2529/files#diff-d50bcaa212383b262a507ceb3c0ef3c1761c093178a30c94387946ea90cf3c9eR4

Copy link
Collaborator

@mongodben mongodben left a comment

Choose a reason for hiding this comment

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

lgtm w a couple small things! nice work on this tricky one!

@krollins-mdb krollins-mdb merged commit 5c0c73c into mongodb:realm-react-guidance Jan 31, 2023
mongodben added a commit that referenced this pull request Feb 10, 2023
The Open and Close a Realm page needed a nearly complete overhaul
because these concepts are very different with `@realm/react`.

I plan to re-evaluate the "Key Concept" section after we've finished the
current Realm React epic.

- https://jira.mongodb.org/browse/DOCSP-26995

- [Configure a
Realm](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26995/sdk/react-native/realm-database/configure-a-realm/)

If your PR modifies the docs, you might need to also update some
corresponding
pages. Check if completed or N/A.

- [x] Create Jira ticket for corresponding docs-app-services update(s),
if any
- [x] Checked/updated Admin API
- [x] Checked/updated CLI reference

[REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)

![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTC2T1wlVitCxsZHwKb18NazHbiFmtF0_FeNw&usqp=CAU)

---------

Co-authored-by: Ben Perlmutter <[email protected]>
krollins-mdb added a commit to krollins-mdb/docs-realm that referenced this pull request Feb 13, 2023
The Open and Close a Realm page needed a nearly complete overhaul
because these concepts are very different with `@realm/react`.

I plan to re-evaluate the "Key Concept" section after we've finished the
current Realm React epic.

- https://jira.mongodb.org/browse/DOCSP-26995

- [Configure a
Realm](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26995/sdk/react-native/realm-database/configure-a-realm/)

If your PR modifies the docs, you might need to also update some
corresponding
pages. Check if completed or N/A.

- [x] Create Jira ticket for corresponding docs-app-services update(s),
if any
- [x] Checked/updated Admin API
- [x] Checked/updated CLI reference

[REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)

![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTC2T1wlVitCxsZHwKb18NazHbiFmtF0_FeNw&usqp=CAU)

---------

Co-authored-by: Ben Perlmutter <[email protected]>
krollins-mdb added a commit to krollins-mdb/docs-realm that referenced this pull request Feb 16, 2023
The Open and Close a Realm page needed a nearly complete overhaul
because these concepts are very different with `@realm/react`.

I plan to re-evaluate the "Key Concept" section after we've finished the
current Realm React epic.

- https://jira.mongodb.org/browse/DOCSP-26995

- [Configure a
Realm](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26995/sdk/react-native/realm-database/configure-a-realm/)

If your PR modifies the docs, you might need to also update some
corresponding
pages. Check if completed or N/A.

- [x] Create Jira ticket for corresponding docs-app-services update(s),
if any
- [x] Checked/updated Admin API
- [x] Checked/updated CLI reference

[REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)

![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTC2T1wlVitCxsZHwKb18NazHbiFmtF0_FeNw&usqp=CAU)

---------

Co-authored-by: Ben Perlmutter <[email protected]>
mongodben added a commit that referenced this pull request Mar 21, 2023
The Open and Close a Realm page needed a nearly complete overhaul
because these concepts are very different with `@realm/react`.

I plan to re-evaluate the "Key Concept" section after we've finished the
current Realm React epic.

- https://jira.mongodb.org/browse/DOCSP-26995

- [Configure a
Realm](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26995/sdk/react-native/realm-database/configure-a-realm/)

If your PR modifies the docs, you might need to also update some
corresponding
pages. Check if completed or N/A.

- [x] Create Jira ticket for corresponding docs-app-services update(s),
if any
- [x] Checked/updated Admin API
- [x] Checked/updated CLI reference

[REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)

![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTC2T1wlVitCxsZHwKb18NazHbiFmtF0_FeNw&usqp=CAU)

---------

Co-authored-by: Ben Perlmutter <[email protected]>
@krollins-mdb krollins-mdb deleted the DOCSP-26995 branch March 24, 2023 13:34
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