From 519f20491c8724c806cadd367e6f047681d22e86 Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Sat, 23 Aug 2014 13:40:50 +0100 Subject: [PATCH] update based on changes to watchDir() --- docs/API-Reference.md | 44 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/docs/API-Reference.md b/docs/API-Reference.md index 5908b46..0ac1e74 100644 --- a/docs/API-Reference.md +++ b/docs/API-Reference.md @@ -232,7 +232,9 @@ Walter Higgins * [utils.find() function](#utilsfind-function) * [utils.serverAddress() function](#utilsserveraddress-function) * [utils.watchFile() function](#utilswatchfile-function) + * [utils.watchDir() function](#utilswatchdir-function) * [utils.unwatchFile() function](#utilsunwatchfile-function) + * [utils.unwatchDir() function](#utilsunwatchdir-function) * [utils.array() function](#utilsarray-function) * [Drone Plugin](#drone-plugin) * [Constructing a Drone Object](#constructing-a-drone-object) @@ -2326,11 +2328,11 @@ The following example illustrates how to use http.request to make a request to a var http = require('./http/request'); http.request( - { + { url: 'http://pixenate.com/pixenate/pxn8.pl', method: 'POST', params: {script: '[]'} - }, + }, function( responseCode, responseBody ) { var jsObj = eval('(' + responseBody + ')'); }); @@ -2865,6 +2867,28 @@ utils.watchFile( 'test.txt', function( file ) { console.log( file + ' has changed'); }); ``` +### utils.watchDir() function + +Watches for changes to the given directory and calls the function provided +when the directory changes. It works by calling watchFile/watchDir for each +file/subdirectory. + +#### Parameters + + * Dir - the file to watch (can be a file or directory) + * Callback - The callback to invoke when the directory has changed. + The callback takes the changed file as a parameter. + For each change inside the directory the callback will also + be called. + +#### Example + +```javascript +var utils = require('utils'); +utils.watchDir( 'players/_ial', function( dir ) { + console.log( dir + ' has changed'); +}); +``` ### utils.unwatchFile() function Removes a file from the watch list. @@ -2875,6 +2899,22 @@ var utils = require('utils'); utils.unwatchFile( 'test.txt'); ``` +### utils.unwatchDir() function + +Removes a directory from the watch list and all files inside the directory +are also "unwatched" + +#### Example +```javascript +var utils = require('utils'); +utils.unwatchDir ('players/_ial'); +``` +Would cause also +```javascript +utils.unwatchFile (file); +``` +for each file inside directory (and unwatchDir for each directory inside it) + ### utils.array() function Converts Java collection objects to type Javascript array so they can avail of