|
243 | 243 | // Update a value within a transaction. Calling this is the |
244 | 244 | // equivalent of calling `transaction()` on a Firebase reference. |
245 | 245 | // |
246 | | - // * `updateFn`: A developer-supplied function which will be passed the current data |
247 | | - // stored at this location (as a Javascript object). The function should |
248 | | - // return the new value it would like written (as a Javascript object). |
249 | | - // If "undefined" is returned (i.e. you "return;" with no arguments) the |
250 | | - // transaction will be aborted and the data at this location will not be modified. |
251 | | - // * `applyLocally`: By default, events are raised each time the transaction update function runs. So |
252 | | - // if it is run multiple times, you may see intermediate states. You can set this |
253 | | - // to false to suppress these intermediate states and instead wait until the |
| 246 | + // * `updateFn`: A developer-supplied function which will be passed |
| 247 | + // the current data stored at this location (as a |
| 248 | + // Javascript object). The function should return the |
| 249 | + // new value it would like written (as a Javascript |
| 250 | + // object). If "undefined" is returned (i.e. you |
| 251 | + // "return;" with no arguments) the transaction will |
| 252 | + // be aborted and the data at this location will not |
| 253 | + // be modified. |
| 254 | + // * `applyLocally`: By default, events are raised each time the |
| 255 | + // transaction update function runs. So if it is run |
| 256 | + // multiple times, you may see intermediate states. |
| 257 | + // You can set this to false to suppress these |
| 258 | + // intermediate states and instead wait until the |
254 | 259 | // transaction has completed before events are raised. |
255 | 260 | // |
256 | | - // This function returns a promise that will be resolved when the transaction function has completed. |
257 | | - // A successful transaction is resolved with the snapshot. If the transaction is aborted, |
| 261 | + // This function returns a promise that will be resolved when the |
| 262 | + // transaction function has completed. A successful transaction is |
| 263 | + // resolved with the snapshot. If the transaction is aborted, |
258 | 264 | // the promise will be resolved with null. |
259 | 265 | object.$transaction = function(updateFn, applyLocally) { |
260 | 266 | var deferred = self._q.defer(); |
261 | | - self._fRef.ref().transaction(updateFn, function(err, committed, snapshot) { |
262 | | - if(err) { |
263 | | - deferred.reject(err); |
264 | | - } else if(!committed) { |
265 | | - deferred.resolve(null); |
266 | | - } else { |
267 | | - deferred.resolve(snapshot); |
268 | | - } |
269 | | - }, applyLocally); |
| 267 | + self._fRef.ref().transaction(updateFn, |
| 268 | + function(err, committed, snapshot) { |
| 269 | + if (err) { |
| 270 | + deferred.reject(err); |
| 271 | + } else if (!committed) { |
| 272 | + deferred.resolve(null); |
| 273 | + } else { |
| 274 | + deferred.resolve(snapshot); |
| 275 | + } |
| 276 | + }, |
| 277 | + applyLocally); |
270 | 278 | }; |
271 | 279 |
|
272 | | - |
273 | 280 | // Remove this object from the remote data. Calling this is the |
274 | 281 | // equivalent of calling `remove()` on a Firebase reference. This |
275 | 282 | // function takes a single optional argument: |
|
0 commit comments