Skip to content

Commit 61a8052

Browse files
committed
Added function that checks if there's any changes in the channel's localQueue
1 parent aeef89d commit 61a8052

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/simperium/channel.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,11 @@ LocalQueue.prototype.queue = function( change ) {
574574
if ( !this.ready ) return;
575575

576576
this.processQueue( change.id );
577-
}
578-
;
577+
};
578+
579+
LocalQueue.prototype.hasChanges = function() {
580+
return Object.keys(this.queues).length > 0;
581+
};
579582

580583
LocalQueue.prototype.dequeueChangesFor = function( id ) {
581584
var changes = [], sent = this.sent[id], queue = this.queues[id];

src/simperium/client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Client.prototype.bucket = function( name ) {
7171

7272
if ( this.open ) channel.onConnect();
7373

74+
bucket.hasLocalChanges = function() {
75+
return channel.localQueue.hasChanges();
76+
};
77+
7478
return bucket;
7579
};
7680

test/simperium/channel_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,29 @@ describe( 'Channel', function() {
310310
} );
311311
} );
312312

313+
it( 'should have local changes on send', function( done ) {
314+
channel.once( 'send', function() {
315+
assert.equal( channel.localQueue.hasChanges(), true );
316+
done();
317+
} );
318+
319+
store.put( '123', 3, {title: 'hello world'} ).then( function() {
320+
bucket.update( '123', {title: 'goodbye world!!'} );
321+
} );
322+
} );
323+
324+
it( 'should have no local changes after ack', function( done ) {
325+
channel.on( 'acknowledge', function() {
326+
assert.equal( channel.localQueue.hasChanges(), false );
327+
done();
328+
} );
329+
330+
store.put( '123', 3, {title: 'hello world'} ).then( function() {
331+
bucket.update( '123', {title: 'goodbye world!!'} );
332+
done();
333+
} );
334+
} );
335+
313336
// If receiving a remote change while there are unsent local modifications,
314337
// local changes should be rebased onto the new ghost and re-sent
315338
it( 'should resolve applying patch to modified object', function( done ) {

0 commit comments

Comments
 (0)