Class BaseCollection<T>

Represents a collection of some models that extends from BaseModel instances. BaseCollection is basically a wrapper around array of Models

Type Parameters

  • T extends BaseModel

    Type parameter extending BaseModel.

Hierarchy (view full)

Constructors

Properties

_listeners: Listeners = {}

Event listeners registered for this instance.

_uid: string = ...

Unique identifier for the instance.

loading: boolean = false

Indicates if the collection is currently loading.

models: T[]

The array of models in the collection.

Accessors

  • get $class(): string
  • Gets the class name of this instance.

    Returns string

Methods

  • Adds a model to the collection. If the provided item is a plain object, it is converted into a model before adding.

    Parameters

    • item: any

      The item to add.

    Returns void

  • Returns a map of API functions with default values.

    Returns Endpoints

    An object containing API functions.

  • Initiates a bulk create or update operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the bulk create or update operation.

    Returns Promise<any>

    A Promise representing the bulk create or update operation.

  • Initiates a bulk delete operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the bulk delete operation.

    Returns Promise<any>

    A Promise representing the bulk delete operation.

  • Initiates a create operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the create operation.

    Returns Promise<any>

    A Promise representing the create operation.

  • Creates a new model instance with the provided attributes.

    Parameters

    • attributes: any

      The attributes for the new model.

    Returns undefined | T

    • The created model instance, or undefined if model is not defined.
  • Initiates a delete operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the delete operation.

    Returns Promise<any>

    A Promise representing the delete operation.

  • Performs an asynchronous operation with loading indicator.

    Parameters

    • func: Function

      The function to execute.

    • Rest ...args: any[]

      Additional arguments for the function.

    Returns Promise<any>

    A Promise representing the result of the operation.

  • Clears the collection by removing all models.

    Returns void

  • Emits an event by name to all registered listeners on that event. Listeners will be called in the order that they were added. If a listener returns false, no other listeners will be called.

    Parameters

    • event: any

      The name of the event to emit.

    • Rest ...args: any[]

      The context of the event, passed to listeners.

    Returns void

  • Initiates a fetch operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the fetch operation.

    Returns Promise<any>

    A Promise representing the fetch operation.

  • Finds the index of a model in the collection based on its unique ID (_uid).

    Parameters

    • item: T

      The model to find.

    Returns number

    • The index of the model in the collection, or -1 if not found.
  • Retrieves the models in the collection.

    Returns T[]

    • The array of models in the collection.
  • Makes a request using the provided request function and payload.

    Parameters

    • payload: any

      The payload for the request.

    • reqFunc: any

      The request function to execute.

    Returns Promise<any>

    A Promise representing the request operation.

  • Returns the model type or constructor for the collection.

    Returns undefined | null | typeof BaseModel | T

    • The model type or constructor.
  • Registers an event listener for a given event.

    Event names can be comma-separated to register multiple events.

    Parameters

    • event: string

      The name of the event to listen for.

    • listener: Function

      The event listener, accepts context.

    Returns void

  • Overrides a model in the collection with a new model instance. If the model to override is not found, no action is taken.

    Parameters

    • item: T

      The new model instance to use for override.

    Returns void

  • Initiates a read operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the read operation.

    Returns Promise<any>

    A Promise representing the read operation.

  • Removes a model from the collection.

    Parameters

    • item: T

      The model to remove.

    Returns void

  • Sets the models in the collection.

    Parameters

    • data: any

      The data to set as models.

    Returns void

  • Transforms the provided data into models.

    Parameters

    • data: T[]

      The data to transform.

    Returns T[]

    • The transformed models.

    Example

    // A common use case for vue.js where you can redefine it like so
    transformModels(data: T[]): T[] {
    return reactive(data);
    }
  • Initiates an update operation using provided payload.

    Parameters

    • payload: any = null

      The payload for the update operation.

    Returns Promise<any>

    A Promise representing the update operation.

Generated using TypeDoc