Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Record

A trackable object with configurable save handler. Changes to the object can be reverted incrementally in the reverse order the changes were made.

Hierarchy

  • EventEmitter
  • EventEmitter
    • Record

Indexable

[key: string]: any

A trackable object with configurable save handler. Changes to the object can be reverted incrementally in the reverse order the changes were made.

Index

Constructors

constructor

  • Parameters

    Returns Record

  • Parameters

    • Optional options: RecordOptions | Record
    • Optional data: RecordData

    Returns Record

Properties

listeners

listeners: EventListener[] = []

Accessors

maxListeners

  • get maxListeners(): number
  • set maxListeners(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

virtuals

Methods

changes

  • changes(count?: number): RecordChange[]
  • changes(count?: number): RecordChange[]
  • Return the changes since last save() or init(). By default, it returns all changes.

    Parameters

    • Default value count: number = null

      Number of changes to return (in reverse chronological order).

    Returns RecordChange[]

  • Parameters

    • Optional count: number

    Returns RecordChange[]

commit

  • commit(data: string | number | boolean | RecordData | Record, virtuals?: RecordVirtualProperties): void
  • commit(data: string | number | boolean | RecordData | Record, virtuals?: RecordVirtualProperties): void
  • Parameters

    Returns void

  • Parameters

    • data: string | number | boolean | RecordData | Record
    • Optional virtuals: RecordVirtualProperties

    Returns void

emit

  • emit(namespace: string, ...data: any[]): void
  • Parameters

    • namespace: string
    • Rest ...data: any[]

    Returns void

get

  • get(key: (string | number)[] | string): any
  • get(key: (string | number)[] | string): any
  • Convenience method for returning value at key in _data. key can be a string or Array describing the path under _data.

    Parameters

    • key: (string | number)[] | string

      The path under _data.

    Returns any

    The value at key under _data.

  • Parameters

    • key: (string | number)[] | string

    Returns any

init

  • Initialize the instance. Data passed here is assumed to be the ground truth with respect to changes. All previous changes are cleared on each call.

    Parameters

    Returns void

  • Parameters

    • data: Record | RecordData
    • Optional virtuals: RecordVirtualProperties

    Returns void

on

  • on(namespace: string | RegExp, callback: Function, once?: boolean): EventListener
  • Subscribe a callable function to a namespace.

    Parameters

    • namespace: string | RegExp
    • callback: Function
    • Default value once: boolean = false

    Returns EventListener

    Used to manage the subscription status via open and close methods.

once

  • once(namespace: string | RegExp, callback: Function): EventListener
  • Subscribe a callable function to a namespace, for exactly one execution.

    Parameters

    • namespace: string | RegExp
    • callback: Function

    Returns EventListener

    Used to manage the subscription status via open and close methods.

pop

  • pop(listener: EventListener): boolean
  • Remove a Listener instance from the EventNamespace instance. Called with unsubscribe method.

    Parameters

    • listener: EventListener

    Returns boolean

    A true value indicates a successful pop.

push

  • push(listener: EventListener): void
  • Add a Listener instance to the EventNamespace instance. Called with subscribe method.

    Parameters

    • listener: EventListener

    Returns void

revert

  • revert(count?: number): void
  • revert(count?: number): void
  • Reverts changes to _data made by set() and unset() methods.

    Parameters

    • Default value count: number = this._changes.length

      The number of changes to revert (in reverse chronological order). By default, all changes are reverted.

    Returns void

  • Parameters

    • Optional count: number

    Returns void

save

  • save(): Promise<void>
  • save(): Promise<void>
  • Calls _save() (if it exists). All changes are considered committed if _save exists and returns successfully.

    Returns Promise<void>

  • Returns Promise<void>

serialize

  • serialize(condition?: "save" | "serialize"): RecordData
  • serialize(condition?: "save" | "serialize"): RecordData
  • Serialize the Record instance as an object. Called by #toJSON().

    Parameters

    • Default value condition: "save" | "serialize" = "serialize"

    Returns RecordData

  • Parameters

    • Optional condition: "save" | "serialize"

    Returns RecordData

set

  • set(key: any, value: any, silent?: boolean): boolean
  • set(key: any, value: any, silent?: boolean): boolean
  • Set a value at key in _data. Anything set using this method will have a corresponding entry in _changes.

    Parameters

    • key: any
    • value: any
    • Default value silent: boolean = false

    Returns boolean

  • Parameters

    • key: any
    • value: any
    • Optional silent: boolean

    Returns boolean

toJSON

unset

  • unset(key: any, silent?: boolean): boolean
  • unset(key: any, silent?: boolean): boolean
  • Essentially deletes a property at key under _data. Uses of this method will have a corresponding entry in _changes so long as a value exists. Virtual properties cannot be unset.

    Parameters

    • key: any
    • Default value silent: boolean = false

    Returns boolean

    If true, unset was successful. If false, there's nothing set at key under _data or it is a virtual property.

  • Parameters

    • key: any
    • Optional silent: boolean

    Returns boolean

validate

  • validate(): Promise<void>
  • validate(): Promise<void>
  • Returns Promise<void>

  • Returns Promise<void>