-
Notifications
You must be signed in to change notification settings - Fork 88
(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
(DOCSP-26995) Reframe RN SDK open and close realm page #2529
Conversation
Readability for Commit Hash: 1726539 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.
|
@@ -0,0 +1,20 @@ | |||
// :snippet-start: create-realm-context |
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.
why is this file Models/index.js
, not just Models.js
?
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.
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.
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.
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';
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.
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
?
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.
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 |
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.
Open more than one realm | |
Open Multiple Realms |
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.
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.
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 that case, what about 'More than One' like you originally had it?
since you already talk about just the 'one realm' case above
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 |
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.
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.
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.
Yeah, that makes a lot of sense. Thanks for pointing this out.
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>``. |
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.
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:
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>`. |
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.
note: this relates to below comment https://github.com/mongodb/docs-realm/pull/2529/files#r1090797122
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.
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.
Co-authored-by: Ben Perlmutter <[email protected]>
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. |
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.
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>`` |
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.
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?
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're right. The config happens in the previous section. I've updated locally. Will be in my next commit.
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.
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.
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.
nice improvements! back to you w some smaller items throughout.
@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 |
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.
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
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.
lgtm w a couple small things! nice work on this tricky one!
Co-authored-by: Ben Perlmutter <[email protected]>
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)  --------- Co-authored-by: Ben Perlmutter <[email protected]>
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)  --------- Co-authored-by: Ben Perlmutter <[email protected]>
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)  --------- Co-authored-by: Ben Perlmutter <[email protected]>
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)  --------- Co-authored-by: Ben Perlmutter <[email protected]>
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.
Review Guidelines
REVIEWING.md
Animal wearing a hat