console.log(watch.display)
The display name of the watch.
the ids as refs of the records that in error and can't be watched on the server.
The ids of the records that are in error and can't be watched on the server.
Returns the poll rate in seconds.
const pollRate = watch.pollRate
The poll rate for this watch.
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
The poll rate.
StaticwatchesReturns a list of watches.
hs.Watch.watches.forEach((watch: Watch): void => {
console.log(`We have watch: ${watch.display}`)
})
A list of all open watches.
Add records to watch.
await watch.add('@someid')
The ids to add.
Add the dicts to the watch's grid.
This method can be overridden to track grid mutations.
The dicts to add to the grid.
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),
})
The built callback handler.
Clear all watched items from the watch.
Please note, this will not close the watch or remove any associated method handlers.
await watch.clear()
Clear all callback event handlers on the watch.
// Clear all callbacks from the watch.
watch.clearCallbacks()
The emitter instance.
Empty the grid.
This method can be overridden to track grid mutations.
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()
Fire an event callback.
The event object.
The emitter instance.
Return the callbacks for the event type or all callbacks if the event type is not specified.
const anArrayOfCallbacks = watch.getCallbacks()
OptionaleventType: WatchEventTypeOptional event type.
The callbacks.
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...
}
OptionaleventType: WatchEventTypeTrue if there are callbacks.
Return true if the id or the record is currently in error.
The id or record to test.
True if the id is in error.
True if the watch has errors.
Dump the watch to the local console output.
watch.inspect()
The value instance.
Dump the watch's subject to the local console output.
watch.inspectSubject()
The value instance.
Returns true if the watch is closed.
if (watch.isClosed()) {
// Do something
}
True if the watch is closed. A closed watch can no longer be used.
Remove an event handler from a watch.
watch.off(WatchEventType.Changed, cb)
event type to remove.
callback to remove.
The emitter instance.
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!
})
The event type to add the event for.
The callback handler.
The emitter instance.
Request a watch poll.
Please note, polls are normally handled automatically so manually calling this is not normally required.
Completely refresh the watch.
await watch.refresh()
Remove records to watch.
This is called to stop watching records.
await watch.remove('@someid')
The ids to remove.
Called to remove dicts from the watch's grid.
This method can be overridden to track grid mutations.
The filter to remove items by.
A string representation of a watch.
Update the grid with the new events information.
StaticcloseClose 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.
The subject to close watches for.
StaticinspectInspect all the watches available.
hs.Watch.inspectAll()
StaticopenStaticupdateUpdate the grid with the new events.
A cache of ids to dict indexes in the grid.
The grid to update.
The events to update the grid with.
A haystack Watch.