Skip to content

Commit 0c5e346

Browse files
committed
Pass the args from channel.update through to the bucket.update emit.
1 parent cebb92f commit 0c5e346

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/simperium/bucket.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ export default function Bucket( name, storeProvider, channel ) {
149149
*/
150150
this.onChannelIndex = this.emit.bind( this, 'index' );
151151
this.onChannelError = this.emit.bind( this, 'error' );
152-
this.onChannelUpdate = ( id, data ) => {
153-
this.update( id, data, { sync: false } );
152+
this.onChannelUpdate = ( id, data, original, patch, isIndexing ) => {
153+
this.update( id, data, original, patch, isIndexing, { sync: false } );
154154
};
155155

156156
this.onChannelIndexingStateChange = ( isIndexing ) => {
@@ -215,7 +215,7 @@ Bucket.prototype.reload = function() {
215215
*/
216216
Bucket.prototype.add = function( object, callback ) {
217217
var id = uuid();
218-
return this.update( id, object, callback );
218+
return this.update( id, object, null, null, null, null, callback );
219219
};
220220

221221
/**
@@ -234,12 +234,15 @@ Bucket.prototype.get = function( id, callback ) {
234234
*
235235
* @param {String} id - the bucket id for the object to update
236236
* @param {Object} data - object literal to replace the object data with
237+
* @param {Object} original - the original object before the udpate
238+
* @param {Object} patch - the JSONDiff patch to apply to the object
239+
* @param {Boolean} isIndexing - true if the bucket is currently indexing
237240
* @param {Object} [options] - optional settings
238241
* @param {Boolean} [options.sync=true] - false if object should not be synced with this update
239242
* @param {?bucketStoreGetCallback} callback - executed when object is updated localy
240243
* @returns {Promise<Object>} - update data
241244
*/
242-
Bucket.prototype.update = function( id, data, options, callback ) {
245+
Bucket.prototype.update = function( id, data, original, patch, isIndexing, options, callback ) {
243246
if ( typeof options === 'function' ) {
244247
callback = options;
245248
options = { sync: true };
@@ -251,7 +254,7 @@ Bucket.prototype.update = function( id, data, options, callback ) {
251254

252255
const task = this.storeAPI.update( id, data, this.isIndexing )
253256
.then( bucketObject => {
254-
this.emit( 'update', id, bucketObject.data );
257+
this.emit( 'update', id, bucketObject.data, original, patch, isIndexing );
255258
this.channel.update( bucketObject, options.sync );
256259
return bucketObject;
257260
} );

test/simperium/bucket_test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe( 'Bucket', () => {
3939
const id = 'thing',
4040
object = {one: 'two'};
4141

42-
bucket.update( id, object, function() {
42+
bucket.update( id, object, null, null, null, function() {
4343
bucket.get( id, function( err, savedObject ) {
4444
deepEqual( object, savedObject );
4545
done();
@@ -51,7 +51,7 @@ describe( 'Bucket', () => {
5151
const id = 'thing',
5252
object = {one: 'two'}
5353

54-
bucket.update( id, object, {}, function() {
54+
bucket.update( id, object, null, null, null, {}, function() {
5555
bucket.get( id, function( err, savedObject ) {
5656
deepEqual( object, savedObject );
5757
done();
@@ -99,4 +99,3 @@ describe( 'Bucket', () => {
9999
} );
100100
} );
101101
} );
102-

test/simperium/channel_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ describe( 'Channel', function() {
266266
}, reject );
267267
} );
268268

269-
bucket.update( key, {title: 'hello world'}, function() {
269+
bucket.update( key, {title: 'hello world'}, null, null, null, function() {
270270
channel.handleMessage( 'c:' + JSON.stringify( [{
271271
o: '-', ev: 1, cv: 'cv1', id: key
272272
}] ) );

0 commit comments

Comments
 (0)