12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 'use strict';
- define(['underscore', '../../lib/@waca/dashboard-common/dist/core/Collection'], function (_, Collection) {
- var TransactionalCollection = null;
-
- TransactionalCollection = Collection.extend({
- init: function init() {
- TransactionalCollection.inherited('init', this, arguments);
- },
-
- startTransaction: function startTransaction() {
- if (this._transactionLog) {
- throw new Error('A transaction is already started');
- }
- this._transactionLog = new Collection(this.toJSON(), { modelClass: this.model });
- },
-
- stopTransaction: function stopTransaction() {
- if (!this._transactionLog) {
- throw new Error('No transaction to stop');
- }
- var transactionLog = this._transactionLog;
- this._transactionLog = null;
- TransactionalCollection.inherited('reset', this, [transactionLog.toJSON()]);
- }
- });
-
-
- var collectionFns = _.union(['add', 'remove', 'reset', 'set', 'getModels', 'get', 'toJSON'], Collection._underscoreMethods, Collection._underscoreAttributeMethods);
- _.each(collectionFns, function (method) {
- TransactionalCollection.prototype[method] = function () {
- if (this._transactionLog) {
- return this._transactionLog[method].apply(this._transactionLog, arguments);
- }
- return TransactionalCollection.inherited(method, this, arguments);
- };
- });
- return TransactionalCollection;
- });
|