Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

Commit

Permalink
Merge pull request #26 from YetiOr/master
Browse files Browse the repository at this point in the history
No need in Duplex stream. Rewrite to Readable.
  • Loading branch information
Andrew Abramov committed Mar 28, 2015
2 parents 367f4eb + 5b8887e commit 7f5c635
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
28 changes: 11 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var fs = require('fs'),
path = require('path'),
bemNaming = require('bem-naming'),
PassThrough = require('stream').PassThrough,
Readable = require('stream').Readable,
schemes = require('./schemes');

module.exports = function (levels, options) {
options || (options = {});

var output = new PassThrough({ objectMode: true }),
var output = new Readable({ objectMode: true }),
defaultScheme = options.scheme || schemes.nested,
defaultNaming = options.naming ? bemNaming(options.naming) : bemNaming;

Expand All @@ -27,7 +27,7 @@ module.exports = function (levels, options) {
});

function add(obj) {
output.write(obj);
output.push(obj);
}

function scan(level, callback) {
Expand Down Expand Up @@ -72,22 +72,16 @@ module.exports = function (levels, options) {
}
}

var n = 0,
l = levels.length;
var n = levels.length;

if (l === 0) {
output.end();
} else {
for (var i = 0; i < l; ++i) {
scan(levels[i], scancb);
}
}
output._read = function () {
n || output.push(null);

function scancb(err) {
err && output.emit('error', err);

++n === l && output.end();
}
levels.length && scan(levels.shift(), function (err) {
err && output.emit('error', err);
--n || output.push(null);
});
};

return output;
};
11 changes: 6 additions & 5 deletions test/schemes/flat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ describe('flat scheme', function () {
it('must throw error if levels is not found', function (done) {
var walker = walk(['not-existing-level']);

walker.on('error', function (err) {
err.must.throw();
done();
})
.resume();
walker
.on('error', function (err) {
err.must.throw();
done();
})
.resume();
});

describe('ignore', function () {
Expand Down
11 changes: 6 additions & 5 deletions test/schemes/nested.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ describe('nested scheme', function () {
it('must throw error if levels is not found', function (done) {
var walker = walk(['not-existing-level']);

walker.on('error', function (err) {
err.must.throw();
done();
})
.resume();
walker
.on('error', function (err) {
err.must.throw();
done();
})
.resume();
});

describe('ignore', function () {
Expand Down

0 comments on commit 7f5c635

Please sign in to comment.