Skip to content

Commit 16ebf16

Browse files
authored
Merge pull request #54 from Simperium/add/object-local-changes
Added bucket.hasLocalChanges method
2 parents aeef89d + dedf579 commit 16ebf16

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simperium",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "A simperium client for node.js",
55
"main": "./lib/simperium/index.js",
66
"repository": {

src/simperium/bucket.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Bucket.prototype.update = function( id, data, options, callback ) {
3131
return this.store.update( id, data, this.isIndexing, callback );
3232
};
3333

34+
Bucket.prototype.hasLocalChanges = function( callback ) {
35+
callback( null, false );
36+
};
37+
3438
Bucket.prototype.getVersion = function( id, callback ) {
3539
callback( null, 0 );
3640
};

src/simperium/channel.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ export default function Channel( appid, access_token, bucket, store ) {
293293
collectionRevisions( channel, id, callback );
294294
};
295295

296+
bucket.hasLocalChanges = function( callback ) {
297+
callback( null, channel.localQueue.hasChanges() );
298+
};
299+
296300
bucket.getVersion = function( id, callback ) {
297301
store.get( id ).then(
298302
( ghost ) => {
@@ -574,8 +578,11 @@ LocalQueue.prototype.queue = function( change ) {
574578
if ( !this.ready ) return;
575579

576580
this.processQueue( change.id );
577-
}
578-
;
581+
};
582+
583+
LocalQueue.prototype.hasChanges = function() {
584+
return Object.keys(this.queues).length > 0;
585+
};
579586

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

test/simperium/channel_test.js

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

313+
it( 'should have local changes on send', function( done ) {
314+
channel.once( 'send', function() {
315+
bucket.hasLocalChanges( ( error, hasChanges ) => {
316+
assert.equal( hasChanges, true );
317+
done();
318+
} );
319+
} );
320+
321+
store.put( '123', 3, {title: 'hello world'} ).then( function() {
322+
bucket.update( '123', {title: 'goodbye world!!'} );
323+
} );
324+
} );
325+
313326
// If receiving a remote change while there are unsent local modifications,
314327
// local changes should be rebased onto the new ghost and re-sent
315328
it( 'should resolve applying patch to modified object', function( done ) {

0 commit comments

Comments
 (0)