BaseModel

BaseModel

// ⚠️ you probably do not need to import this directly it is an abstract base class implicity
// used by other models
import BaseModel from "https://designftw.github.io/chat-lib/src/models/BaseModel.js";

Base class for all models

Constructor

# new BaseModel(options)

Constructor for the base model.

Parameters:
Name Type Description
options object
Properties
Name Type Description
id string

see BaseModel's id property

createdAt Date

see BaseModel's createdAt property

updatedAt Date

see BaseModel's updatedAt property

Members

# createdAt :Date

The date that the model was created. Handled by the server and does not need to be set by the client.

Practical Examples

Sort messages in ascending order by their createdAt date:

messages.sort((a, b) => a.createdAt - b.createdAt);
Type:
  • Date

# id :string

The id of the model.

Unique across all models of the same type. For example, the id of a Message is unique across all messages. The id of an Identity is unique across all identities. However the id of a Message may coincidentally be the same as the id of an Identity.

Type:
  • string

# updatedAt :Date

The date that the model was last updated. Handled by the server and does not need to be set by the client.

Practical Examples

Sort messages in ascending order by when they were last edited:

messages.sort((a, b) => a.createdAt - b.createdAt);
Type:
  • Date

Methods

# toJSON() → {Object}

Convert this entity to a JSON object that could be fed to its constructor to create another object with the same data

Returns:
Type
Object