Create a RealmObject
wrapping an Obj
from the binding.
Static
allowStatic
Optional
asymmetricOptionally specify that the schema should sync unidirectionally if using flexible sync when using @realm/babel-plugin.
Static
Optional
embeddedOptionally specify that the schema is an embedded schema when using @realm/babel-plugin.
Static
Optional
primaryOptionally specify the primary key of the schema when using @realm/babel-plugin.
Add a listener callback
which will be called when a live object instance changes.
A TypeAssertionError if callback
is not a function.
wine.addListener((obj, changes) => {
// obj === wine
console.log(`object is deleted: ${changes.deleted}`);
console.log(`${changes.changedProperties.length} properties have been changed:`);
changes.changedProperties.forEach(prop => {
console.log(` ${prop}`);
});
})
Adding the listener is an asynchronous operation, so the callback is invoked the first time to notify the caller when the listener has been added.
Thus, when the callback is invoked the first time it will contain empty array for changes.changedProperties
.
A function to be called when changes occur.
Please use Object.entries()
An array of key/value pairs of the object's properties.
Please use Object.keys()
An array of the names of the object's properties.
Returns all the objects that link to this object in the specified relationship.
An AssertionError if the relationship is not valid.
The type of the objects that link to this object's type.
The name of the property that references objects of this object's type.
The Results that link to this object.
The schema for the type this object belongs to.
The CanonicalObjectSchema that describes this object.
Remove the listener callback
from this object.
A TypeAssertionError if callback
is not a function.
A function previously added as listener
The plain object representation for JSON serialization. Use circular JSON serialization libraries such as @ungap/structured-clone and flatted to stringify Realm entities that have circular structures.
Optional
_: stringOptional
cache: unknownA plain object.
Generated using TypeDoc
Base class for a Realm Object.
Example
To define a class
Person
with requiredname
andage
properties, define astatic schema
:Example
If using the @realm/babel-plugin: To define a class
Person
with requiredname
andage
properties, they would need to be specified in the type argument when it is being constructed to allow Typescript-only model definitions:See
ObjectSchema
Type Param
T
- The type of this class (e.g. if your class isPerson
,T
should also bePerson
- this duplication is required due to how TypeScript works)Type Param
RequiredProperties
- The names of any properties of this class which are required when an instance is constructed withnew
. Any properties not specified will be optional, and will default to a sensible null value if no default is specified elsewhere.