A haystack Watch.

Constructors

  • Constructs a new watch.

    Please note, all watches must be closed when no longer used.

    Parameters

    • watchDisplay: string

      A client side display name for the watch.

    • subject: Subject

      The watch will observe this subject.

    • grid: HGrid = ...

      An empty grid to use for the watch.

    Returns Watch

Properties

grid: HGrid

The grid for the watch.

Accessors

  • get errorRefs(): HRef[]
  • Returns HRef[]

    the ids as refs of the records that in error and can't be watched on the server.

  • get errors(): string[]
  • Returns string[]

    The ids of the records that are in error and can't be watched on the server.

  • get pollRate(): number
  • Returns the poll rate in seconds.

    const pollRate = watch.pollRate
    

    Returns number

    The poll rate for this watch.

  • set pollRate(pollRate: number): void
  • Attempt to set a new poll rate in seconds for the watch.

    Please note, this value may be ignored.

    // Set the poll rate to 10 seconds.
    watch.pollRate = 10

    Parameters

    • pollRate: number

      The poll rate.

    Returns void

  • get watches(): Watch[]
  • Returns a list of watches.

    hs.Watch.watches.forEach((watch: Watch): void => {
    console.log(`We have watch: ${watch.display}`)
    })

    Returns Watch[]

    A list of all open watches.

Methods

  • Add the dicts to the watch's grid.

    This method can be overridden to track grid mutations.

    Parameters

    • dicts: HDict[]

      The dicts to add to the grid.

    Returns void

  • Builds a changed callback handler based upon the parameters.

    Please note, the returned callback should be used to unregister the callback handler from the watch.

    // Add event handlers. We're only interested in 'curVal' changes.
    watch.changed({
    interests: ['curVal'],
    callback: (event) => console.log(event)
    })

    ...

    // Add event handlers. We're only interested in changes to curVal when it's above
    // a certain value.
    watch.changed({
    interests: ['curVal'],
    condition: 'curVal > 50°F',
    callback: event => console.log(event),
    })

    Parameters

    • __namedParameters: { callback: WatchEventCallback; condition?: string; interests?: string[] }

    Returns WatchEventCallback

    The built callback handler.

    An error if the haystack filter is invalid.

  • Clear all watched items from the watch.

    Please note, this will not close the watch or remove any associated method handlers.

    await watch.clear()
    

    Returns Promise<void>

  • Clear all callback event handlers on the watch.

    // Clear all callbacks from the watch.
    watch.clearCallbacks()

    Returns this

    The emitter instance.

  • Close the watch.

    After this has been called, the underlying watch will be destroyed and will be no longer active. The watch is effectively 'dead' after this has been called.

    // We must always close a watch once we've finished using it.
    await watch.close()

    Returns Promise<void>

  • Return true if there are callback handlers for the specified event type.

    If there event type is not specified then check to see if there are any callback handlers.

    if (watch.hasCallbacks()) {
    // Do something...
    }

    Parameters

    Returns boolean

    True if there are callbacks.

  • Return true if the id or the record is currently in error.

    Parameters

    • id: string | HRef | HDict

      The id or record to test.

    Returns boolean

    True if the id is in error.

  • Dump the watch's subject to the local console output.

    watch.inspectSubject()
    

    Returns this

    The value instance.

  • Returns true if the watch is closed.

    if (watch.isClosed()) {
    // Do something
    }

    Returns boolean

    True if the watch is closed. A closed watch can no longer be used.

  • Add an event handler for the specified event type.

    This is used to listen for watch events.

    watch.on(WatchEventType.Changed, (event: WatchEvent, emitter: WatchEventEmitter): void {
    // Do something with the event!
    })

    Parameters

    Returns this

    The emitter instance.

    An error if the watch is already closed.

  • Request a watch poll.

    Please note, polls are normally handled automatically so manually calling this is not normally required.

    Returns Promise<void>

  • Remove records to watch.

    This is called to stop watching records.

    await watch.remove('@someid')
    

    Parameters

    • ids: Ids

      The ids to remove.

    Returns Promise<void>

  • Called to remove dicts from the watch's grid.

    This method can be overridden to track grid mutations.

    Parameters

    • filter: string

      The filter to remove items by.

    Returns void

  • Update the grid with the new events information.

    Parameters

    • __namedParameters: {
          events: { [prop: string]: WatchChanged };
          idsToGridIndexes: { [prop: string]: number };
      }

    Returns void

  • Close all watches for the given subject.

    Please note, this method doesn't normally need to be called and is designed to be used internally. If you want to close a watch then please just call Watch.#close() instead.

    Parameters

    • subject: Subject

      The subject to close watches for.

    Returns Promise<void>

  • Return a new opened watch.

    Please note, all watches must be closed when no longer used.

    Parameters

    • __namedParameters: { display: string; grid?: HGrid; ids: Ids; subject: Subject }

    Returns Promise<Watch>

    An opened watch.

  • Update the grid with the new events.

    Parameters

    • idsToGridIndexes: { [prop: string]: number }

      A cache of ids to dict indexes in the grid.

    • grid: HGrid

      The grid to update.

    • events: { [prop: string]: WatchChanged }

      The events to update the grid with.

    Returns void