From a35b158fd117f9d5fd448614002549b069713ff0 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 8 Aug 2016 13:48:19 -0700 Subject: [PATCH] [Persistence] Add JSDoc for Transaction --- .../commonUI/edit/src/services/Transaction.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/platform/commonUI/edit/src/services/Transaction.js b/platform/commonUI/edit/src/services/Transaction.js index 1583b7a503..803536be4d 100644 --- a/platform/commonUI/edit/src/services/Transaction.js +++ b/platform/commonUI/edit/src/services/Transaction.js @@ -20,11 +20,26 @@ * at runtime from the About dialog for additional information. *****************************************************************************/ define([], function () { + /** + * A Transaction represents a set of changes that are intended to + * be kept or discarded as a unit. + * @param $log Angular's `$log` service, for logging messages + * @constructor + * @memberof platform/commonUI/edit/services + */ function Transaction($log) { this.$log = $log; this.callbacks = []; } + /** + * Add a change to the current transaction, as expressed by functions + * to either keep or discard the change. + * @param {Function} commit called when the transaction is committed + * @param {Function} cancel called when the transaction is cancelled + * @returns {Function) a function which may be called to remove this + * pair of callbacks from the transaction + */ Transaction.prototype.add = function (commit, cancel) { var callback = { commit: commit, cancel: cancel }; this.callbacks.push(callback); @@ -35,10 +50,28 @@ define([], function () { }.bind(this); }; + /** + * Get the number of changes in the current transaction. + * @returns {number} the size of the current transaction + */ Transaction.prototype.size = function () { return this.callbacks.length; }; + /** + * Keep all changes associated with this transaction. + * @method {platform/commonUI/edit/services.Transaction#commit} + * @returns {Promise} a promise which will resolve when all callbacks + * have been handled. + */ + + /** + * Discard all changes associated with this transaction. + * @method {platform/commonUI/edit/services.Transaction#cancel} + * @returns {Promise} a promise which will resolve when all callbacks + * have been handled. + */ + ['commit', 'cancel'].forEach(function (method) { Transaction.prototype[method] = function () { var promises = [];