Class ModelAbstract

The Model class represents a local data resource. It provides methods to persist changes via the API.

Hierarchy

Constructors

Properties

data: ModelData = {}

The resource object from the API.

exists: boolean = false

Whether or not the resource exists on the server.

freshness: Date = ...

The time at which the model's data was last updated. Watching the value of this property is a fast way to retain/cache a subtree if data hasn't changed.

store: Store

The data store that this resource should be persisted to.

Methods

  • Construct a path to the API endpoint for this resource.

    Returns string

  • Get one of the model's attributes.

    Final

    Type Parameters

    • T = unknown

    Parameters

    • attribute: string

    Returns T

  • Send a request to delete the resource.

    Parameters

    • body: undefined | null | Document | XMLHttpRequestBodyInit | object & {
          [id: string]: any;
      } = {}

      Data to send along with the DELETE request.

    • options: Omit<FlarumRequestOptions<void>, "url"> = {}

    Returns Promise<void>

  • Get the model's ID.

    Final

    Returns undefined | string

  • Generate a function which returns the value of the given attribute.

    Type Parameters

    • T

    Parameters

    • name: string

    Returns (() => T)

      • (): T
      • Generate a function which returns the value of the given attribute.

        Returns T

  • Type Parameters

    • T

    • O = unknown

    Parameters

    • name: string
    • transform: ((attr: O) => T)
        • (attr: O): T
        • Parameters

          • attr: O

          Returns T

    Returns (() => T)

      • (): T
      • Returns T

  • Generate a function which returns the value of the given has-many relationship.

    Returns

    false if no information about the relationship exists; an array if it does, containing models if they have been loaded, and undefined for those that have not.

    Type Parameters

    Parameters

    • name: string

    Returns (() => false | (undefined | M)[])

      • (): false | (undefined | M)[]
      • Generate a function which returns the value of the given has-many relationship.

        Returns

        false if no information about the relationship exists; an array if it does, containing models if they have been loaded, and undefined for those that have not.

        Returns false | (undefined | M)[]

  • Generate a function which returns the value of the given has-one relationship.

    Returns

    false if no information about the relationship exists; undefined if the relationship exists but the model has not been loaded; or the model if it has been loaded.

    Type Parameters

    Parameters

    • name: string

    Returns (() => false | M)

      • (): false | M
      • Generate a function which returns the value of the given has-one relationship.

        Returns

        false if no information about the relationship exists; undefined if the relationship exists but the model has not been loaded; or the model if it has been loaded.

        Returns false | M

  • Type Parameters

    Parameters

    • name: string

    Returns (() => null | false | M)

      • (): null | false | M
      • Returns null | false | M

  • Transform the given value into a Date object.

    Parameters

    • value: string

    Returns Date

  • Parameters

    • value: null | string

    Returns null | Date

  • Parameters

    • value: undefined | string

    Returns undefined | Date

  • Parameters

    • value: undefined | null | string

    Returns undefined | null | Date

Generated using TypeDoc v0.23.24