sharedb 4.1.2 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,7 +61,9 @@ Presence.prototype.destroy = function(callback) {
61
61
  [
62
62
  function(next) {
63
63
  async.each(localIds, function(presenceId, next) {
64
- presence.localPresences[presenceId].destroy(next);
64
+ var localPresence = presence.localPresences[presenceId];
65
+ if (!localPresence) return next();
66
+ localPresence.destroy(next);
65
67
  }, next);
66
68
  },
67
69
  function(next) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sharedb",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "description": "JSON OT database backend",
5
5
  "main": "lib/index.js",
6
6
  "dependencies": {
@@ -146,6 +146,32 @@ describe('Presence', function() {
146
146
  ], errorHandler(done));
147
147
  });
148
148
 
149
+ it('does not throw if LocalPresence destroys before Presence', function(done) {
150
+ var localPresence1 = presence1.create('presence-1');
151
+
152
+ async.series([
153
+ presence1.subscribe.bind(presence1),
154
+ function(next) {
155
+ // Middleware that ensures the presence update replies before the
156
+ // unsubscribe, so the local presence is destroyed first
157
+ var replies = [];
158
+ backend.use('reply', function(message, cb) {
159
+ if (!replies) return cb();
160
+ if (message.reply.a !== 'p') return replies.push(cb);
161
+ var _replies = replies;
162
+ replies = null;
163
+ cb();
164
+ _replies.forEach(function(reply) {
165
+ reply();
166
+ });
167
+ });
168
+
169
+ presence1.destroy(next);
170
+ localPresence1.destroy(errorHandler(done));
171
+ }
172
+ ], done);
173
+ });
174
+
149
175
  it('throws if trying to create local presence when wanting destroy', function(done) {
150
176
  presence2.destroy(errorHandler(done));
151
177
  expect(function() {