Skip to content

Commit bfdfdf5

Browse files
Mohammad Hunan ChughtaiMohammad Hunan Chughtai
authored andcommitted
(DOCSP-26994): @realm/react-ify 'Define an Asymmetric Object - React Native SDK' (#2468)
## Pull Request Info ### Jira - https://jira.mongodb.org/browse/DOCSP-26994 ### Staged Changes - [Define an Asymmetric Object - React Native SDK](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26994-asymmetric-object/sdk/react-native/realm-database/schemas/asymmetric-object/) ### 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]>
1 parent 530e71c commit bfdfdf5

File tree

5 files changed

+105
-10
lines changed

5 files changed

+105
-10
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Realm from 'realm';
2+
3+
// :snippet-start: js-invoice-schema
4+
class Invoice extends Realm.Object {
5+
static schema = {
6+
name: 'Invoice',
7+
// sync Invoice objects one way from your device to your Atlas database.
8+
asymmetric: true,
9+
primaryKey: '_id',
10+
properties: {
11+
_id: 'objectId',
12+
item: 'string',
13+
quantity: 'int',
14+
price: 'int',
15+
},
16+
};
17+
}
18+
// :snippet-end:
19+
20+
export default Invoice;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Realm from 'realm';
2+
3+
// TODO: Replace `static schema` with TS-first models + realm-babel-plugin (https://www.npmjs.com/package/@realm/babel-plugin) approach once realm-babel-plugin version 0.1.2 releases with bug fixes
4+
// :snippet-start: ts-invoice-schema
5+
class Invoice extends Realm.Object<Invoice> {
6+
_id!: string;
7+
item!: string;
8+
quantity!: number;
9+
price!: number;
10+
11+
static schema = {
12+
name: 'Invoice',
13+
// sync Invoice objects one way from your device to your Atlas database.
14+
asymmetric: true,
15+
primaryKey: '_id',
16+
properties: {
17+
_id: 'objectId',
18+
item: 'string',
19+
quantity: 'int',
20+
price: 'int',
21+
},
22+
};
23+
}
24+
// :snippet-end:
25+
26+
export default Invoice;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Invoice extends Realm.Object {
2+
static schema = {
3+
name: 'Invoice',
4+
// sync Invoice objects one way from your device to your Atlas database.
5+
asymmetric: true,
6+
primaryKey: '_id',
7+
properties: {
8+
_id: 'objectId',
9+
item: 'string',
10+
quantity: 'int',
11+
price: 'int',
12+
},
13+
};
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Invoice extends Realm.Object<Invoice> {
2+
_id!: string;
3+
item!: string;
4+
quantity!: number;
5+
price!: number;
6+
7+
static schema = {
8+
name: 'Invoice',
9+
// sync Invoice objects one way from your device to your Atlas database.
10+
asymmetric: true,
11+
primaryKey: '_id',
12+
properties: {
13+
_id: 'objectId',
14+
item: 'string',
15+
quantity: 'int',
16+
price: 'int',
17+
},
18+
};
19+
}

source/sdk/react-native/realm-database/schemas/asymmetric-object.txt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,33 @@ If you are using Flexible Sync and need to sync a collection unidirectionally
1818
from your device to your Atlas database, you can set the ``asymmetric`` property
1919
on your object schema.
2020

21-
.. example::
21+
Example
22+
~~~~~~~
2223

23-
In the following example of a retail app, the client requires large amounts of
24-
invoice data to be recorded rapidly by store employees. The client specifies
25-
that invoice data does not need to be read after employees have recorded it. To
26-
satisfy this requirement, the application developer defines an invoice
27-
collection with its ``asymmetric`` property set to ``true``.
28-
29-
.. literalinclude:: /examples/generated/node/asymmetric-sync.snippet.asymmetric-sync.js
30-
:language: javascript
31-
:emphasize-lines: 4
24+
In the following example of a retail app, the client requires large amounts of
25+
invoice data to be recorded rapidly by store employees. The client specifies
26+
that invoice data does not need to be read after employees have recorded it. To
27+
satisfy this requirement, the application developer defines an invoice
28+
collection with its ``asymmetric`` property set to ``true``.
29+
30+
.. tabs-realm-languages::
31+
32+
.. tab::
33+
:tabid: typescript
34+
35+
.. literalinclude:: /examples/generated/react-native/ts/Invoice.snippet.ts-invoice-schema.ts
36+
:language: typescript
37+
:emphasize-lines: 9
38+
:linenos:
39+
40+
.. tab::
41+
:tabid: javascript
42+
43+
.. literalinclude:: /examples/generated/react-native/js/Invoice.snippet.js-invoice-schema.js
44+
:language: javascript
45+
:emphasize-lines: 5
46+
:linenos:
47+
3248

3349
.. note:: Attempting to Read Asymmetric Sync Objects
3450

0 commit comments

Comments
 (0)