Skip to content

Commit 8a197c9

Browse files
committed
Merge branch 'master' of github.com:nodekc/keepee
Merging master
2 parents 4639b6a + 23e5bb6 commit 8a197c9

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

client.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ var WriteOperation = function (ws, key, value) {
1313
'success': [],
1414
'fail': []
1515
};
16-
17-
ws.on('confirm', function (d) {
16+
var cb = function (d) {
1817
if (d.id !== id) {
1918
return;
2019
}
2120

2221
this.callbacks['success'].forEach(function (cb) {
2322
cb();
2423
});
25-
}.bind(this));
24+
25+
ws.removeListener(cb);
26+
27+
}.bind(this);
28+
29+
ws.on('confirm', cb);
2630
};
2731

2832
WriteOperation.prototype.commit = function () {
@@ -56,8 +60,15 @@ ReadOperation.prototype.success = function (cb) {
5660
};
5761

5862
var KeePee = function (ws) {
59-
this.data = {};
60-
this.ws = ws;
63+
ws.on('keys', function (keys) {
64+
for (var x in keys) {
65+
var ro = this.read(keys[x]);
66+
67+
ro.success(function (d) {
68+
this.data[d.key] = d;
69+
}.bind(this));
70+
}
71+
}.bind(this));
6172

6273
ws.on('write', function (d) {
6374
this.data[d.key] = d;
@@ -67,6 +78,11 @@ var KeePee = function (ws) {
6778
ws.on('read', function (key) {
6879
ws.emit('read', this.data[key]);
6980
});
81+
82+
ws.emit('keys');
83+
84+
this.data = {};
85+
this.ws = ws;
7086
};
7187

7288
KeePee.prototype.write = function (key, value) {
@@ -85,7 +101,7 @@ KeePee.prototype.read = function (key) {
85101
};
86102

87103

88-
var kp = new KeePee();
104+
var kp = new KeePee(ws);
89105

90106
var writeOperation = kp.write('Foo', 'Bar');
91107

0 commit comments

Comments
 (0)