ActiveClass Methods
All ActiveDocuments - that is, all instances of ES6 classes that extend ActiveClass
- come with some default methods, used for interacting with your Firebase Realtime Database.
Have you initialized?
To interact with your Firebase Realtime Database, you must first initialize
a connection to your Firebase Realtime Database.
getId
Returns the ActiveDocument's _id
property, or generates one if it does not already have one.
Parameters: None
Returns: string
, or throws an error if it tries to generate an _id
but the Firebase Realtime Database is not initialize
d
Example
- JavaScript
- TypeScript
reload
Refreshes the ActiveDocument's properties based on the current database values.
Parameters: None
Returns: Promise<object>
, a promise that resolves into the object reloaded from the database
Example
- JavaScript
- TypeScript
ref
Return the Firebase database Reference for the ActiveDocument or a specified child path.
Parameters:
path
:string
(optional), the path to locate the reference for starting from the root of the ActiveDocument
Returns: a firebase.database.Reference
for the ActiveDocument or a specified child path
save
Saves an ActiveDocument and its current properties to the database
pendingSetters
Returns a promise that resolves when all setter promises have resolved to the database.
syncOpts
Returns (and optionally updates) the current sync settings for the ActiveDocument
Parameters:
opts
:{ toDb?: boolean, fromDb?: boolean }
, optionalopts.toDb
:boolean
, should changes to the document's properties automatically sync to the database automatically (without calling.save
)?opts.fromDb
:boolean
, should changes from the database automatically sync to the document (without callingreload
)?
Returns: { fromDb: boolean, toDb: boolean }
, an object representing the current sync settings for the ActiveDocument
Default settings
create
Active Documents created via the create
method have toDb
and fromDb
syncing on by default.
toDb: true
means that, when you set a property on the ActiveDocument, it automatically syncs to the Firebase Realtime Database;fromDb: true
means that, when the Firebase Realtime Database is updated, it automatically syncs back to the ActiveDocument
new
Active Documents created via the new
constructor have toDb
and fromDb
syncing off by default.
toDb: false
means that, when you set a property on the ActiveDocument, it doesn't automatically sync to the Firebase Realtime Database;fromDb: false
means that, when the Firebase Realtime Database is updated, it doesn't automatically sync back to the ActiveDocument
Updating settings
You can update the sync options for a given ActiveDocument by passing in an object of new settings.
For example, suppose we wanted to turn off automatic syncing from the database for an ActiveDocument instantiated using create
(which has syncing on by default)"