Permalink
Browse files

Allow entries list to be modified by the 'entries' listener

  • Loading branch information...
1 parent e50c4c9 commit dacc0ebf6c6a2a732194310b4a1bebabce1d232f @isaacs isaacs committed Mar 26, 2012
Showing with 16 additions and 6 deletions.
  1. +16 −6 lib/dir-reader.js
View
@@ -36,13 +36,23 @@ DirReader.prototype._getEntries = function () {
var me = this
fs.readdir(me._path, function (er, entries) {
if (er) return me.error(er)
- me._entries = entries
- me._length = entries.length
- // console.error("DR %s sort =", me.path, me.props.sort)
- if (typeof me.props.sort === "function") {
- me._entries.sort(me.props.sort)
+
+ me.emit("entries", entries)
+ if (me._paused) {
+ me.once("resume", processEntries)
+ } else {
+ processEntries()
+ }
+
+ function processEntries () {
+ me._entries = entries
+ me._length = entries.length
+ // console.error("DR %s sort =", me.path, me.props.sort)
+ if (typeof me.props.sort === "function") {
+ me._entries.sort(me.props.sort)
+ }
+ me._read()
}
- me._read()
})
}

0 comments on commit dacc0eb

Please sign in to comment.