Watcher
Overview
Type: class
An event manager that can be subscribed to and unsubscribed from, and the events can be fired to actively listening handlers.
class WatcherWatcher<Args extends any[]> { }
Constructor
constructor()
Parameters
The constructor does not take any parameters.
Example
import { Watcher } from 'cotton-box'
const watcher = new Watcher()
const unwatch = watcher.watch(() => { ... })
watcher.refresh(...) // Arguments can be passed
unwatch()
Properties
There are no publicly available properties.
Methods
watch
Accepts a callback that serves as a handler and start watching for changes. The callback will be invoked whenever a refresh is triggered.
watch(callback: ((...args: Args) => void)): (() => void)
refresh
Triggers a refresh to all handlers subscribed to the watcher.
refresh(...args: Args): void
unwatchAll
Forcefully removes all active handlers.
unwatchAll(): void
dispose
Removes all active handlers and prevent new ones from being added.
dispose(): void