| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 432cb35 commit 11d6f1a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,14 +109,19 @@ non-UTF-8 encoded Buffers to `fs` functions will not work as expected. | |||
| 109 | 109 | added: v0.5.8 | |
| 110 | 110 | --> | |
| 111 | 111 | ||
| 112 | - Objects returned from `fs.watch()` are of this type. | ||
| 112 | + Objects returned from [`fs.watch()`][] are of this type. | ||
| 113 | + | ||
| 114 | + The `listener` callback provided to `fs.watch()` receives the returned FSWatcher's | ||
| 115 | + `change` events. | ||
| 116 | + | ||
| 117 | + The object itself emits these events: | ||
| 113 | 118 | ||
| 114 | 119 | ### Event: 'change' | |
| 115 | 120 | <!-- YAML | |
| 116 | 121 | added: v0.5.8 | |
| 117 | 122 | --> | |
| 118 | 123 | ||
| 119 | - * `event` {String} The type of fs change | ||
| 124 | + * `eventType` {String} The type of fs change | ||
| 120 | 125 | * `filename` {String | Buffer} The filename that changed (if relevant/available) | |
| 121 | 126 | ||
| 122 | 127 | Emitted when something changes in a watched directory or file. | |
@@ -128,7 +133,8 @@ support. If `filename` is provided, it will be provided as a `Buffer` if | |||
| 128 | 133 | `filename` will be a string. | |
| 129 | 134 | ||
| 130 | 135 | ```js | |
| 131 | - fs.watch('./tmp', {encoding: 'buffer'}, (event, filename) => { | ||
| 136 | + // Example when handled through fs.watch listener | ||
| 137 | + fs.watch('./tmp', {encoding: 'buffer'}, (eventType, filename) => { | ||
| 132 | 138 | if (filename) | |
| 133 | 139 | console.log(filename); | |
| 134 | 140 | // Prints: <Buffer ...> | |
@@ -1443,10 +1449,13 @@ directory. The returned object is a [`fs.FSWatcher`][]. | |||
| 1443 | 1449 | The second argument is optional. If `options` is provided as a string, it | |
| 1444 | 1450 | specifies the `encoding`. Otherwise `options` should be passed as an object. | |
| 1445 | 1451 | ||
| 1446 | - The listener callback gets two arguments `(event, filename)`. `event` is either | ||
| 1452 | + The listener callback gets two arguments `(eventType, filename)`. `eventType` is either | ||
| 1447 | 1453 | `'rename'` or `'change'`, and `filename` is the name of the file which triggered | |
| 1448 | 1454 | the event. | |
| 1449 | 1455 | ||
| 1456 | + Please note the listener callback is attached to the `'change'` event | ||
| 1457 | + fired by [`fs.FSWatcher`][], but they are not the same thing. | ||
| 1458 | + | ||
| 1450 | 1459 | ### Caveats | |
| 1451 | 1460 | ||
| 1452 | 1461 | <!--type=misc--> | |
@@ -1499,8 +1508,8 @@ be provided. Therefore, don't assume that `filename` argument is always | |||
| 1499 | 1508 | provided in the callback, and have some fallback logic if it is null. | |
| 1500 | 1509 | ||
| 1501 | 1510 | ```js | |
| 1502 | - fs.watch('somedir', (event, filename) => { | ||
| 1503 | - console.log(`event is: ${event}`); | ||
| 1511 | + fs.watch('somedir', (eventType, filename) => { | ||
| 1512 | + console.log(`event type is: ${eventType}`); | ||
| 1504 | 1513 | if (filename) { | |
| 1505 | 1514 | console.log(`filename provided: ${filename}`); | |
| 1506 | 1515 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1399,7 +1399,7 @@ function FSWatcher() { | |||
| 1399 | 1399 | this._handle = new FSEvent(); | |
| 1400 | 1400 | this._handle.owner = this; | |
| 1401 | 1401 | ||
| 1402 | - this._handle.onchange = function(status, event, filename) { | ||
| 1402 | + this._handle.onchange = function(status, eventType, filename) { | ||
| 1403 | 1403 | if (status < 0) { | |
| 1404 | 1404 | self._handle.close(); | |
| 1405 | 1405 | const error = !filename ? | |
@@ -1409,7 +1409,7 @@ function FSWatcher() { | |||
| 1409 | 1409 | error.filename = filename; | |
| 1410 | 1410 | self.emit('error', error); | |
| 1411 | 1411 | } else { | |
| 1412 | - self.emit('change', event, filename); | ||
| 1412 | + self.emit('change', eventType, filename); | ||
| 1413 | 1413 | } | |
| 1414 | 1414 | }; | |
| 1415 | 1415 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments