registerHandler (func,opts) // can be called at any time but unexpected problems may arise if called when watcher is already async start(opts) // starts the watcher which will initializes the files indexing and set the handler function
stop() // stops
remove() completly removes the current watcher.
async restart(opts,force) // first stops the watcher then calls start, if force is true it will reintialize the watcher as well
getWatcher // returns handle to choikar watcher for choikar methods access
```
### getters
watching
ready
### events
changed: filepath, type // when a watched file has a change (type will be added,removed,or modified)
error: message,error
watching: state,options // listening for changes
ready: state, options // done indexing files to be watched
### handler
#### default
the built in default handler is probably sufficient for most use cases. It emits a 'changed' event with the file or directory name changed and with a type, that being modified, deleted, added. The default handler also emits a 'install' event if the file is package.json in the root of the source is modified (used for restarting), or a warning if it is deleted or added
```javascript
function _handler (type, f) {
log.debug(`file ${f} was ${type}`)
const fname = path.basename(f)
if ( fname.toLowerCase() === 'package.json' && path.dirname(f)=== this.opts.source.replace(/\/$/, ''))
if (type !=='modified') {
const msg = `a package.json in root of ${this.opts.source} was added or removed`
log.warning(msg)
this.emit('warning',f,msg)
return
} else{
this.emit('install', f)
}
// user might want to run debounce on the listener for this event
log.debug({file:f, type:type, msg:'file system changed, emitting'})
this.emit('changed', f,type)
} // end handler
```
#### custom
one can use a custom handler by passing such a function in options or using registerHandler. The handler is passed two arguments the type of the change and the file changed.