Skip to content

Commit 4177b4d

Browse files
author
Mohammad Hunan Chughtai
committed
(DOCSP-26994): @realm/react-ify 'Asymmetric Object - React Native SDK'
1 parent e86e607 commit 4177b4d

File tree

5 files changed

+103
-10
lines changed

5 files changed

+103
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
asymmetric: true,
14+
primaryKey: '_id',
15+
properties: {
16+
_id: 'objectId',
17+
item: 'string',
18+
quantity: 'int',
19+
price: 'int',
20+
},
21+
};
22+
}
23+
// :snippet-end:
24+
25+
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
asymmetric: true,
10+
primaryKey: '_id',
11+
properties: {
12+
_id: 'objectId',
13+
item: 'string',
14+
quantity: 'int',
15+
price: 'int',
16+
},
17+
};
18+
}

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)