Options
Menu

Class HistoricalModel

This is an alternate read-only representation of a particular RealTimeModel that allows for the introspection of the model's contents at particular points in time. History can only be traversed by version ID, but the timestamp associated with a particular version is available when this model has been "played" to that version.

The backward, forward, and playTo methods are the means for "playing" the model to a particular version or version offset.

Just like in a RealTimeModel, you can use the root and elementAt methods to access the data associated with this model's "current" version. Note that these return a read-only HistoricalObject or HistoricalElement respectively.

See the developer guide for some examples and additional information.

Hierarchy

  • HistoricalModel

Implements

Index

Properties

Events

Events: HistoricalModelEvents = HistoricalModelEventConstants

Methods

backward

  • backward(delta?: number): Promise<void>
  • "Plays" the current version of this model backward by the given number of versions.

    Parameters

    • delta: number = 1

      the number of versions to move backward

    Returns Promise<void>

    A Promise, which on resolve indicates that the playback has completed.

collectionId

  • collectionId(): string

createdTime

  • createdTime(): Date

elementAt

  • Given a search path, returns a read-only representation of the element at that path at the current played-to version, or null if no such element exists.

    Parameters

    • path: Path

      the search path for querying within this model's contents

    Returns HistoricalElement<any>

  • Given an array of search path elements, returns a read-only representation of the element at that path at the current played-to version, or null if no such element exists.

    Parameters

    • ...elements: PathElement[]

      an array of search path elements (which in totality are a Path)

    Returns HistoricalElement<any>

forward

  • forward(delta?: number): Promise<void>
  • "Plays" the current version of this model forward by the given number of versions.

    Parameters

    • delta: number = 1

      the number of versions to move forward

    Returns Promise<void>

    A Promise, which on resolve indicates that the play forward has completed.

isTransitioning

  • isTransitioning(): boolean
  • Returns true when the model is in the process of playing to a particular version:

    historicalModel.version() // 433
    historicalModel.isTransitioning() // false
    historicalModel.playTo(1)
      .then(() => {
        historicalModel.version() // 1
        historicalModel.isTransitioning() // false
      })
    historicalModel.isTransitioning() // true
    

    Returns boolean

    true if this model is in the process of playing to a particular version

maxTime

  • maxTime(): Date
  • The most recent timestamp at which this model was modified

    Returns Date

maxVersion

  • maxVersion(): number

minTime

  • minTime(): Date

minVersion

  • minVersion(): number
  • The oldest version of this model. Versions are 0-based, so this will just return 0.

    Returns number

modelId

  • modelId(): string

playTo

  • playTo(version: number): Promise<void>
  • Enables "playing" the current model to the given version number. This is an asynchronous call because it may take some time to traverse over potentially thousands of versions of this model.

    The returned promise resolves when the playback process is complete. At this point calling version, time, root and elementAt will return the data / metadata of this model at the desired version.

    Parameters

    • version: number

      the version of the model at which point in time you're interested.

    Returns Promise<void>

    A promise that will be resolved when the model has arrived at the requested version.

playToTime

  • playToTime(time: Date): Promise<void>
  • Enables "playing" the current model to the given version it was at, at a specific point in time. If the time corresponds exactly to a time an operation was applied to the model, the model will be played to that version. If the time does not correspond directly to a model version then the model will be played to the version corresponding to the most recent operation before the time request. This is because that would have been the state of the model had a user opened it at that time.

    This is an asynchronous call because it may take some time to traverse over potentially thousands of versions of this model.

    The returned promise resolves when the playback process is complete. At this point calling version, time, root and elementAt will return the data / metadata of this model at the desired version.

    Parameters

    • time: Date

      the time to play back the model to.

    Returns Promise<void>

    A promise that will be resolved when the model has arrived at the requested time.

root

session

targetVersion

  • targetVersion(): number
  • This is the "desired" version of this model. During the period when the model is in the process of playing back, this returns the targeted version. Otherwise it represents the current version.

    historicalModel.version() // 433
    historicalModel.targetVersion() // 433
    historicalModel.playTo(1)
      .then(() => {
        historicalModel.version() // 1
      })
    historicalModel.targetVersion() // 1
    historicalModel.version() // 433, because `playTo` is async
    

    Returns number

time

  • time(): Date
  • The timestamp at which the current (played to) version was created. This can be used to determine the timestamp associated with a particular version of this model. For example:

    historicalModel.version() // 433
    historicalModel.time() // "Fri Aug 16 2019 11:49:19 GMT-0600"
    historicalModel.playTo(410)
      .then(() => {
        historicalModel.version() // 410
        historicalModel.time() // "Fri Aug 16 2019 11:44:36 GMT-0600"
    
        return historicalModel.playTo(1);
      })
      .then(() => {
        // this is the timestamp at which the model was created
        historicalModel.time() // "Wed Aug 14 2019 13:51:01 GMT-0600"
      })
    

    Returns Date

    the timestamp associated with this model's current version

version

  • version(): number
  • The current version of this model. E.g.

    historicalVersion.maxVersion() // 433
    historicalModel.version() // 433
    historicalModel.playTo(410)
      .then(() => {
        historicalModel.version() // 410
    
        return historicalModel.playTo(1);
      })
      .then(() => {
        historicalModel.version() // 1
      })
    

    Returns number