r113854 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113853‎ | r113854 | r113855 >
Date:21:02, 14 March 2012
Author:catrope
Status:deferred
Tags:
Comment:
Put the invert state / method (commit or rollback) in the TransactionProcessor object and no longer pass it as a parameter to each operation. This makes it easier for operations to execute other operations.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js
@@ -44,28 +44,28 @@
4545 },
4646 'replace': {
4747 'commit': function( op ) {
48 - this.replace( op, false );
 48+ this.replace( op );
4949 },
5050 'rollback': function( op ) {
51 - this.replace( op, true );
 51+ this.replace( op );
5252 }
5353 },
5454 // Change element attributes
5555 'attribute': {
5656 'commit': function( op ) {
57 - this.attribute( op, false );
 57+ this.attribute( op );
5858 },
5959 'rollback': function( op ) {
60 - this.attribute( op, true );
 60+ this.attribute( op );
6161 }
6262 },
6363 // Change content annotations
6464 'annotate': {
6565 'commit': function( op ) {
66 - this.mark( op, false );
 66+ this.mark( op );
6767 },
6868 'rollback': function( op ) {
69 - this.mark( op, true );
 69+ this.mark( op );
7070 }
7171 }
7272 };
@@ -88,9 +88,9 @@
8989 return this.operations[this.operationIndex++] || false;
9090 };
9191
92 -ve.dm.TransactionProcessor.prototype.executeOperation = function( op, method ) {
 92+ve.dm.TransactionProcessor.prototype.executeOperation = function( op ) {
9393 if ( op.type in ve.dm.TransactionProcessor.operationMap ) {
94 - ve.dm.TransactionProcessor.operationMap[op.type][method].call( this, op );
 94+ ve.dm.TransactionProcessor.operationMap[op.type][this.method].call( this, op );
9595 } else {
9696 throw 'Invalid operation error. Operation type is not supported: ' + operation.type;
9797 }
@@ -98,10 +98,16 @@
9999
100100 ve.dm.TransactionProcessor.prototype.process = function( method ) {
101101 var op;
 102+ // Store the method (commit or rollback) and the operations array so executeOperation()
 103+ // can access them easily
 104+ this.method = method;
102105 this.operations = this.transaction.getOperations();
 106+
 107+ // This loop is factored this way to allow operations to be skipped over or executed
 108+ // from within other operations
103109 this.operationIndex = 0;
104110 while ( ( op = this.nextOperation() ) ) {
105 - this.executeOperation( op, method );
 111+ this.executeOperation( op );
106112 }
107113 };
108114
@@ -454,8 +460,9 @@
455461 }
456462 };
457463
458 -ve.dm.TransactionProcessor.prototype.replace = function( op, invert ) {
459 - var remove = invert ? op.replacement : op.remove,
 464+ve.dm.TransactionProcessor.prototype.replace = function( op ) {
 465+ var invert = this.method == 'rollback',
 466+ remove = invert ? op.replacement : op.remove,
460467 replacement = invert ? op.remove : op.replacement;
461468 // remove is provided only for OT / conflict resolution and for
462469 // reversibility, we don't actually verify it here
@@ -468,8 +475,9 @@
469476
470477 };
471478
472 -ve.dm.TransactionProcessor.prototype.attribute = function( op, invert ) {
473 - var element = this.model.data[this.cursor];
 479+ve.dm.TransactionProcessor.prototype.attribute = function( op ) {
 480+ var invert = this.method == 'rollback',
 481+ element = this.model.data[this.cursor];
474482 if ( element.type === undefined ) {
475483 throw 'Invalid element error. Can not set attributes on non-element data.';
476484 }
@@ -506,8 +514,9 @@
507515 }
508516 };
509517
510 -ve.dm.TransactionProcessor.prototype.mark = function( op, invert ) {
511 - var target;
 518+ve.dm.TransactionProcessor.prototype.mark = function( op ) {
 519+ var invert = this.method == 'rollback',
 520+ target;
512521 if ( ( op.method === 'set' && !invert ) || ( op.method === 'clear' && invert ) ) {
513522 target = this.set;
514523 } else if ( ( op.method === 'clear' && !invert ) || ( op.method === 'set' && invert ) ) {

Status & tagging log