File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,12 @@ records before this event fires. Writing records however should be fine.
107
107
` length ` is the amount of records the database is holding. This only counts each
108
108
key once, even if it had been overwritten.
109
109
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
+
110
116
### dirty event: 'drain' ()
111
117
112
118
Emitted whenever all records have been written to disk.
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ var Dirty = exports.Dirty = function(path) {
25
25
this . _fdWrite = null ;
26
26
27
27
this . _load ( ) ;
28
+ return this ;
28
29
} ;
29
30
30
31
util . inherits ( Dirty , EventEmitter ) ;
Original file line number Diff line number Diff line change @@ -97,3 +97,22 @@ describe('test-size', function() {
97
97
assert . equal ( db . size ( ) , 3 ) ;
98
98
} ) ;
99
99
} ) ;
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments