-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(DOCSP-26995) Reframe RN SDK open and close realm page (#2529)
## 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 - https://jira.mongodb.org/browse/DOCSP-26995 ### Staged Changes - [Configure a Realm](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26995/sdk/react-native/realm-database/configure-a-realm/) ### Reminder Checklist 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 ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md) ### Animal wearing a hat ![](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTC2T1wlVitCxsZHwKb18NazHbiFmtF0_FeNw&usqp=CAU) --------- Co-authored-by: Ben Perlmutter <[email protected]>
- Loading branch information
1 parent
7820869
commit 5c0c73c
Showing
18 changed files
with
369 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// :snippet-start: create-realm-context | ||
import {createRealmContext} from '@realm/react'; | ||
// Import all of your models. | ||
import Invoice from './Models/Invoice'; | ||
import Business from './Models/Business'; | ||
// :remove-start: | ||
import Address from './Models/Address'; | ||
import Contact from './Models/Contact'; | ||
// :remove-end: | ||
|
||
export const RealmContext = createRealmContext({ | ||
// Pass all of your models into the schema value. | ||
schema: [Invoice, Business], | ||
}); | ||
// :snippet-end: | ||
|
||
export const SecondRealmContext = createRealmContext({ | ||
// Pass all of your secondary models into the schema value. | ||
schema: [Address, Contact], | ||
}); | ||
|
||
// :snippet-start: in-memory-realm | ||
export const InMemoryRealmContext = createRealmContext({ | ||
schema: [Address, Contact], | ||
inMemory: true, | ||
}); | ||
// :snippet-end: |
39 changes: 39 additions & 0 deletions
39
examples/react-native/__tests__/ts/realm-database/configure-realm-local.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// :snippet-start: configure-realm | ||
import React from 'react'; | ||
import {RealmContext} from '../RealmConfig'; | ||
// :remove-start: | ||
import {render} from '@testing-library/react-native'; | ||
import {useApp} from '@realm/react'; | ||
import {View, Text} from 'react-native'; | ||
|
||
const APP_ID = 'example-testers-kvjdy'; | ||
|
||
function MyApp() { | ||
const app = useApp(); | ||
|
||
if (app.id !== APP_ID) { | ||
throw new Error('Did not instantiate app client'); | ||
} | ||
|
||
return ( | ||
<View> | ||
<Text>Foo</Text> | ||
</View> | ||
); | ||
} | ||
// :remove-end: | ||
|
||
function AppWrapperLocal() { | ||
const {RealmProvider} = RealmContext; | ||
|
||
return ( | ||
<RealmProvider> | ||
<MyApp /> | ||
</RealmProvider> | ||
); | ||
} | ||
// :snippet-end: | ||
|
||
test('Instantiate RealmProvider correctly', () => { | ||
render(<AppWrapperLocal />); | ||
}); |
67 changes: 67 additions & 0 deletions
67
examples/react-native/__tests__/ts/realm-database/configure-realm-multiple.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// :snippet-start: two-realm-contexts | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; | ||
import {RealmContext} from '../RealmConfig'; | ||
import {SecondRealmContext} from '../RealmConfig'; | ||
// :remove-start: | ||
import {render} from '@testing-library/react-native'; | ||
import {useApp} from '@realm/react'; | ||
import {View, Text} from 'react-native'; | ||
|
||
const APP_ID = 'example-testers-kvjdy'; | ||
|
||
function AppSectionOne() { | ||
const app = useApp(); | ||
|
||
if (app.id !== APP_ID) { | ||
throw new Error('Did not instantiate app client'); | ||
} | ||
|
||
return ( | ||
<View> | ||
<Text>Foo</Text> | ||
</View> | ||
); | ||
} | ||
|
||
function AppSectionTwo() { | ||
const app = useApp(); | ||
|
||
if (app.id !== APP_ID) { | ||
throw new Error('Did not instantiate app client'); | ||
} | ||
|
||
return ( | ||
<View> | ||
<Text>Bar</Text> | ||
</View> | ||
); | ||
} | ||
// :remove-end: | ||
|
||
function TwoRealmsWrapper() { | ||
const {RealmProvider: RealmProvider} = RealmContext; | ||
const {RealmProvider: SecondRealmProvider} = SecondRealmContext; | ||
|
||
return ( | ||
<AppProvider id={APP_ID}> | ||
<UserProvider> | ||
{/* This realm uses Flexible Sync. */} | ||
<RealmProvider | ||
sync={{flexible: true, onError: error => console.error(error)}} | ||
> | ||
<AppSectionOne /> | ||
</RealmProvider> | ||
{/* This is a separate local-only realm. */} | ||
<SecondRealmProvider> | ||
<AppSectionTwo /> | ||
</SecondRealmProvider> | ||
</UserProvider> | ||
</AppProvider> | ||
); | ||
} | ||
// :snippet-end: | ||
|
||
test('Instantiate SecondRealmProvider correctly', () => { | ||
render(<TwoRealmsWrapper />); | ||
}); |
44 changes: 44 additions & 0 deletions
44
examples/react-native/__tests__/ts/realm-database/configure-realm-sync.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// :snippet-start: configure-realm-sync | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; | ||
import {RealmContext} from '../RealmConfig'; | ||
// :remove-start: | ||
import {render} from '@testing-library/react-native'; | ||
import {useApp} from '@realm/react'; | ||
import {View, Text} from 'react-native'; | ||
|
||
const APP_ID = 'example-testers-kvjdy'; | ||
|
||
function MyApp() { | ||
const app = useApp(); | ||
|
||
if (app.id !== APP_ID) { | ||
throw new Error('Did not instantiate app client'); | ||
} | ||
|
||
return ( | ||
<View> | ||
<Text>Foo</Text> | ||
</View> | ||
); | ||
} | ||
// :remove-end: | ||
|
||
function AppWrapperSync() { | ||
const {RealmProvider} = RealmContext; | ||
|
||
return ( | ||
<AppProvider id={APP_ID}> | ||
<UserProvider> | ||
<RealmProvider sync={{flexible: true, onError: error => console.error(error)}}> | ||
<MyApp /> | ||
</RealmProvider> | ||
</UserProvider> | ||
</AppProvider> | ||
); | ||
} | ||
// :snippet-end: | ||
|
||
test('Instantiate RealmProvider correctly', () => { | ||
render(<AppWrapperSync />); | ||
}); |
9 changes: 9 additions & 0 deletions
9
source/examples/generated/react-native/js/RealmConfig.snippet.create-realm-context.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {createRealmContext} from '@realm/react'; | ||
// Import all of your models. | ||
import Invoice from './Models/Invoice'; | ||
import Business from './Models/Business'; | ||
|
||
export const RealmContext = createRealmContext({ | ||
// Pass all of your models into the schema value. | ||
schema: [Invoice, Business], | ||
}); |
4 changes: 4 additions & 0 deletions
4
source/examples/generated/react-native/js/RealmConfig.snippet.in-memory-realm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const InMemoryRealmContext = createRealmContext({ | ||
schema: [Address, Contact], | ||
inMemory: true, | ||
}); |
12 changes: 12 additions & 0 deletions
12
...examples/generated/react-native/ts/configure-realm-local.test.snippet.configure-realm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import {RealmContext} from '../RealmConfig'; | ||
|
||
function AppWrapperLocal() { | ||
const {RealmProvider} = RealmContext; | ||
|
||
return ( | ||
<RealmProvider> | ||
<MyApp /> | ||
</RealmProvider> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
...es/generated/react-native/ts/configure-realm-multiple.test.snippet.two-realm-contexts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; | ||
import {RealmContext} from '../../RealmConfig'; | ||
import {SecondRealmContext} from '../../RealmConfig'; | ||
|
||
function TwoRealmsWrapper() { | ||
const {RealmProvider: RealmProvider} = RealmContext; | ||
const {RealmProvider: SecondRealmProvider} = SecondRealmContext; | ||
|
||
return ( | ||
<AppProvider id={APP_ID}> | ||
<UserProvider> | ||
{/* This realm uses Flexible Sync. */} | ||
<RealmProvider | ||
sync={{flexible: true, onError: error => console.error(error)}} | ||
> | ||
<AppSectionOne /> | ||
</RealmProvider> | ||
{/* This is a separate local-only realm. */} | ||
<SecondRealmProvider> | ||
<AppSectionTwo /> | ||
</SecondRealmProvider> | ||
</UserProvider> | ||
</AppProvider> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
...ples/generated/react-native/ts/configure-realm-sync.test.snippet.configure-realm-sync.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; | ||
import {RealmContext} from '../RealmConfig'; | ||
|
||
function AppWrapperSync() { | ||
const {RealmProvider} = RealmContext; | ||
|
||
return ( | ||
<AppProvider id={APP_ID}> | ||
<UserProvider> | ||
<RealmProvider sync={{flexible: true, onError: error => console.error(error)}}> | ||
<MyApp /> | ||
</RealmProvider> | ||
</UserProvider> | ||
</AppProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.