@@ -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 ) => {
@@ -209,13 +209,13 @@ Bucket.prototype.reload = function() {
209209 * Stores an object in the bucket and syncs it to simperium. Generates an
210210 * object ID to represent the object in simperium.
211211 *
212- * @param {Object } object - plain js object literal to be saved/synced
212+ * @param {Object } data - plain js object literal to be saved/synced
213213 * @param {?bucketStoreGetCallback } callback - runs when object has been saved
214214 * @return {Promise<Object> } data stored in the bucket
215215 */
216- Bucket . prototype . add = function ( object , callback ) {
216+ Bucket . prototype . add = function ( data , callback ) {
217217 var id = uuid ( ) ;
218- return this . update ( id , object , callback ) ;
218+ return this . update ( id , data , callback ) ;
219219} ;
220220
221221/**
@@ -234,13 +234,21 @@ 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 } remoteUpdateInfo - object containing data about a remote change
238+ * @param {Object } [updateInfo.original] - the original object before the udpate
239+ * @param {Object } [updateInfo.patch] - the JSONDiff patch to apply to the object
240+ * @param {Boolean } [updateInfo.isIndexing] - true if the bucket is currently indexing
237241 * @param {Object } [options] - optional settings
238242 * @param {Boolean } [options.sync=true] - false if object should not be synced with this update
239243 * @param {?bucketStoreGetCallback } callback - executed when object is updated localy
240244 * @returns {Promise<Object> } - update data
241245 */
242- Bucket . prototype . update = function ( id , data , options , callback ) {
243- if ( typeof options === 'function' ) {
246+ Bucket . prototype . update = function ( id , data , remoteUpdateInfo , options , callback ) {
247+ // Callback could be 3rd or 4th argument
248+ if ( typeof remoteUpdateInfo === 'function' ) {
249+ callback = remoteUpdateInfo ;
250+ options = { sync : true } ;
251+ } else if ( typeof options === 'function' ) {
244252 callback = options ;
245253 options = { sync : true } ;
246254 }
@@ -251,7 +259,7 @@ Bucket.prototype.update = function( id, data, options, callback ) {
251259
252260 const task = this . storeAPI . update ( id , data , this . isIndexing )
253261 . then ( bucketObject => {
254- this . emit ( 'update' , id , bucketObject . data ) ;
262+ this . emit ( 'update' , id , bucketObject . data , remoteUpdateInfo ) ;
255263 this . channel . update ( bucketObject , options . sync ) ;
256264 return bucketObject ;
257265 } ) ;
0 commit comments