Witness (n) 3. One who hears; a listener.
Witness v. 3. to bear witness to; testify to; give or afford evidence of.
The witness is an intelligent file content cache that keeps track ( optionally on a per-caller basis) of the state of a file.
Witness may be installed using Node and npm.
npm install witness
Witness can be used on a individual persistent basis or as a listener.
// For this example assume we have three files layed out as follows:// - src/one.coffee// - src/two.coffee// - src/three.coffee// Require the witness and initialize it.Witness = ;audtior = /* The persistent cache file can be passed in here;defaults to './.witness-cache' */;// Checking the state of some files.witness; // == 'added'witness; // == 'added'witness; // == 'added'witness; // == 'ready'// Now assume we have modified the content of one of 'src/one.coffee'.witness; // == 'changed'witness; // == 'ready'// To allow a single process to maintain its event queue independent of another// in a persistent way, one may specify a context as the second argument// to `witness::state`.witness; // == 'added'witness; // == 'ready'witness; // == 'added'witness; // == 'ready'// Now if we assume we modified the content again. Notice how 'apple' and// 'orange' only get notified about the changed event once.witness; // == 'changed'witness; // == 'changed'witness; // == 'ready'witness; // == 'ready'// This is to be used at the end of process; this writes the in-memory// cache to a persistent file.witness;
Unless otherwise noted, all files contained within this project are liensed under the MIT opensource license. See the included file LICENSE or visit opensource.org for more information.