Home Reference Source
import {Model} from 'arva-js/core/Model.js'
public class | source

Model

Extends:

eventemitter3~EventEmitterPrioritisedObject → Model

Direct Subclass:

LocalModel

A model that has attributes synced with the database.

Example:

export class Box extends Model {
 get label() {}
 get articleNumber() {}
}

Constructor Summary

Public Constructor
public

constructor(id: String, data: Object, options: Object): Model

Creates a new instance of a model.

Method Summary

Public Methods
public

Check if the model has been synchonized with the database

Inherited Summary

From class PrioritisedObject
public get
public get

id: *

public set

id: *

public get

Priority (positioning) of the object in the dataSource

public set
public

Disables pushes of local changes to the dataSource, and stops event emits that refer to the model's data.

public

Enables pushes of local changes to the dataSource, and enables event emits that refer to the model's data. The change listener is active by default, so you'll only need to call this method if you've previously called disableChangeListener().

public

off(event: String, handler: Function, context: Object): void

Removes subscription to events emitted by this PrioritisedArray.

public

on(event: String, handler: Function, context: Object): void

Subscribes to events emitted by this PrioritisedArray.

public

once(event: String, handler: Function, context: Object): void

Subscribes to the given event type exactly once; it automatically unsubscribes after the first time it is triggered.

public

remove(): void

Deletes the current object from the dataSource, and clears itself to free memory.

public

transaction(method: Function): void

Allows multiple modifications to be made to the model without triggering dataSource pushes and event emits for each change.

Public Constructors

public constructor(id: String, data: Object, options: Object): Model source

Creates a new instance of a model.

Override:

PrioritisedObject#constructor

Params:

NameTypeAttributeDescription
id String

Optional: The identifier for this model. For a user model this might be a user ID, for example. It is used to build the path to the dataSource. This path is <root>/<model name appended with 's'>/<id>. If no id is given, a randomly generated one will be pushed to the dataSource. You can use this for creating new objects in the dataSource.

data Object

Optional: The initial data to fill the model with. The model will be extended with any properties present in the data parameter.

options Object

Optional: Additional options. Currently used is "dataSnapshot", which if present is used to fetch the initial model data. If not present, the model will add a one-time subscription to the dataSource to fetch initial data.

Return:

Model

Model Instance.

Public Methods

public synced(): Promise source

Check if the model has been synchonized with the database

Return:

Promise

Resolves when the model has been synchonized with the database