Skip to content

Commit ac7b803

Browse files
committed
Merge pull request #44 from simon-o-matic/master
Added the ability to chain an .on('load') on the constructor.
2 parents 6894f24 + f52d798 commit ac7b803

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ records before this event fires. Writing records however should be fine.
107107
`length` is the amount of records the database is holding. This only counts each
108108
key once, even if it had been overwritten.
109109

110+
You can chain the on load to the contructor as follows:
111+
112+
```javascript
113+
var db = dirty(file).on('load', function() { ... });
114+
```
115+
110116
### dirty event: 'drain' ()
111117

112118
Emitted whenever all records have been written to disk.

lib/dirty/dirty.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var Dirty = exports.Dirty = function(path) {
2525
this._fdWrite = null;
2626

2727
this._load();
28+
return this;
2829
};
2930

3031
util.inherits(Dirty, EventEmitter);

test/test-system.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,22 @@ describe('test-size', function() {
9797
assert.equal(db.size(), 3);
9898
});
9999
});
100+
101+
describe('test-chaining-of-constructor', function() {
102+
var file = config.TMP_PATH + '/chain.dirty';
103+
fs.existsSync(file) && fs.unlinkSync(file);
104+
105+
it('should allow .on load to chain to constructor', function() {
106+
var db = dirty(file);
107+
db.on('load', function() {
108+
db.set("x", "y");
109+
db.set("p", "q");
110+
db.close();
111+
112+
db = dirty(file).on('load', function(size) {
113+
assert.strictEqual(db.size(), 2);
114+
assert.strictEqual(size, 2);
115+
});
116+
});
117+
});
118+
});

0 commit comments

Comments
 (0)