Skip to content

Commit de1cef7

Browse files
committed
If an index is empty immediately complete indexing
1 parent f98cbbd commit de1cef7

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/simperium/channel.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ internal.handleChangeError = function( err, change, acknowledged ) {
189189
}
190190
}
191191

192+
internal.indexingComplete = function() {
193+
// Indexing has finished
194+
this.bucket.isIndexing = false;
195+
this.emit( 'index', this.index_cv );
196+
197+
this.index_last_id = null;
198+
this.index_cv = null;
199+
this.bucket.removeListener( 'update', this.bucketUpdateListener );
200+
}
201+
192202
export default function Channel( appid, access_token, bucket, store ) {
193203
var channel = this;
194204
var message = this.message = new EventEmitter();
@@ -298,13 +308,7 @@ Channel.prototype.onBucketUpdate = function( noteId ) {
298308
if ( this.index_last_id == null || this.index_cv == null ) {
299309
return;
300310
} else if ( this.index_last_id === noteId ) {
301-
// Indexing has finished
302-
this.bucket.isIndexing = false;
303-
this.emit( 'index', this.index_cv );
304-
305-
this.index_last_id = null;
306-
this.index_cv = null;
307-
this.bucket.removeListener( 'update', this.bucketUpdateListener );
311+
internal.indexingComplete.call( this );
308312
}
309313
};
310314

@@ -362,7 +366,12 @@ Channel.prototype.onIndex = function( data ) {
362366
} );
363367

364368
if ( !mark ) {
365-
this.index_last_id = objectId;
369+
if ( objectId ) {
370+
this.index_last_id = objectId;
371+
}
372+
if ( !this.index_last_id ) {
373+
internal.indexingComplete.call( this )
374+
}
366375
this.index_cv = cv;
367376
} else {
368377
this.sendIndexRequest( mark );

0 commit comments

Comments
 (0)