r103516 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103515‎ | r103516 | r103517 >
Date:22:42, 17 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Renamed es.Transaction to es.TransactionModel
Modified paths:
  • /trunk/extensions/VisualEditor/demo/index.html (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/es.Transaction.js (deleted) (history)
  • /trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js (replaced) (history)
  • /trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/models/es.TransactionModel.js (added) (history)
  • /trunk/extensions/VisualEditor/tests/es/es.TransactionProcessor.test.js (replaced) (history)
  • /trunk/extensions/VisualEditor/tests/es/index.html (modified) (history)

Diff [purge]

Property changes on: trunk/extensions/VisualEditor/tests/es/es.TransactionProcessor.test.js
___________________________________________________________________
Deleted: svn:eol-style
11 - native
Index: trunk/extensions/VisualEditor/tests/es/index.html
@@ -18,7 +18,6 @@
1919 <script src="../../modules/qunit/qunit.js"></script>
2020 <script src="../../modules/es/es.js"></script>
2121 <script src="../../modules/es/es.Range.js"></script>
22 - <script src="../../modules/es/es.Transaction.js"></script>
2322 <script src="../../modules/es/es.TransactionProcessor.js"></script>
2423
2524 <!-- Bases -->
@@ -38,6 +37,7 @@
3938 <script src="../../modules/es/models/es.TableCellModel.js"></script>
4039 <script src="../../modules/es/models/es.TableModel.js"></script>
4140 <script src="../../modules/es/models/es.TableRowModel.js"></script>
 41+ <script src="../../modules/es/models/es.TransactionModel.js"></script>
4242
4343 <!-- Tests -->
4444 <script src="es.testData.js"></script>
Index: trunk/extensions/VisualEditor/demo/index.html
@@ -58,7 +58,6 @@
5959 <script src="../modules/es/es.Html.js"></script>
6060 <script src="../modules/es/es.Position.js"></script>
6161 <script src="../modules/es/es.Range.js"></script>
62 - <script src="../modules/es/es.Transaction.js"></script>
6362 <script src="../modules/es/es.TransactionProcessor.js"></script>
6463
6564 <!-- Serializers -->
@@ -90,6 +89,7 @@
9190 <script src="../modules/es/models/es.TableRowModel.js"></script>
9291 <script src="../modules/es/models/es.TableCellModel.js"></script>
9392 <script src="../modules/es/models/es.HeadingModel.js"></script>
 93+ <script src="../modules/es/models/es.TransactionModel.js"></script>
9494
9595 <!-- Views -->
9696 <script src="../modules/es/views/es.SurfaceView.js"></script>
Index: trunk/extensions/VisualEditor/modules/es/es.Transaction.js
@@ -1,137 +0,0 @@
2 -/**
3 - * Creates an es.Transaction object.
4 - *
5 - * @class
6 - * @constructor
7 - * @param {Object[]} operations List of operations
8 - */
9 -es.Transaction = function( operations ) {
10 - this.operations = es.isArray( operations ) ? operations : [];
11 -};
12 -
13 -/* Methods */
14 -
15 -/**
16 - * Gets a list of all operations.
17 - *
18 - * @method
19 - * @returns {Object[]} List of operations
20 - */
21 -es.Transaction.prototype.getOperations = function() {
22 - return this.operations;
23 -};
24 -
25 -/**
26 - * Merges consecutive operations of the same type.
27 - *
28 - * @method
29 - */
30 -es.Transaction.prototype.optimize = function() {
31 - for ( var i = 0; i < this.operations.length - 1; i++ ) {
32 - var a = this.operations[i];
33 - var b = this.operations[i + 1];
34 - if ( a.type === b.type ) {
35 - switch ( a.type ) {
36 - case 'retain':
37 - a.length += b.length;
38 - this.operations.splice( i + 1, 1 );
39 - i--;
40 - break;
41 - case 'insert':
42 - case 'remove':
43 - a.data = a.data.concat( b.data );
44 - this.operations.splice( i + 1, 1 );
45 - i--;
46 - break;
47 - }
48 - }
49 - }
50 -};
51 -
52 -/**
53 - * Adds a retain operation.
54 - *
55 - * @method
56 - * @param {Integer} length Length of content data to retain
57 - */
58 -es.Transaction.prototype.pushRetain = function( length ) {
59 - this.operations.push( {
60 - 'type': 'retain',
61 - 'length': length
62 - } );
63 -};
64 -
65 -/**
66 - * Adds an insertion operation.
67 - *
68 - * @method
69 - * @param {Array} data Data to retain
70 - */
71 -es.Transaction.prototype.pushInsert = function( data ) {
72 - this.operations.push( {
73 - 'type': 'insert',
74 - 'data': data
75 - } );
76 -};
77 -
78 -/**
79 - * Adds a removal operation.
80 - *
81 - * @method
82 - * @param {Array} data Data to remove
83 - */
84 -es.Transaction.prototype.pushRemove = function( data ) {
85 - this.operations.push( {
86 - 'type': 'remove',
87 - 'data': data
88 - } );
89 -};
90 -
91 -/**
92 - * Adds an element attribute change operation.
93 - *
94 - * @method
95 - * @param {String} method Method to use, either "set" or "clear"
96 - * @param {String} key Name of attribute to change
97 - * @param {Mixed} value Value to set attribute to, or value of attribute being cleared
98 - */
99 -es.Transaction.prototype.pushChangeElementAttribute = function( method, key, value ) {
100 - this.operations.push( {
101 - 'type': 'attribute',
102 - 'method': method,
103 - 'key': key,
104 - 'value': value
105 - } );
106 -};
107 -
108 -/**
109 - * Adds a start annotating operation.
110 - *
111 - * @method
112 - * @param {String} method Method to use, either "set" or "clear"
113 - * @param {Object} annotation Annotation object to start setting or clearing from content data
114 - */
115 -es.Transaction.prototype.pushStartAnnotating = function( method, annotation ) {
116 - this.operations.push( {
117 - 'type': 'annotate',
118 - 'method': method,
119 - 'bias': 'start',
120 - 'annotation': annotation
121 - } );
122 -};
123 -
124 -/**
125 - * Adds a stop annotating operation.
126 - *
127 - * @method
128 - * @param {String} method Method to use, either "set" or "clear"
129 - * @param {Object} annotation Annotation object to stop setting or clearing from content data
130 - */
131 -es.Transaction.prototype.pushStopAnnotating = function( method, annotation ) {
132 - this.operations.push( {
133 - 'type': 'annotate',
134 - 'method': method,
135 - 'bias': 'stop',
136 - 'annotation': annotation
137 - } );
138 -};
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js
@@ -665,7 +665,7 @@
666666 * @method
667667 * @param {Integer} offset
668668 * @param {Array} data
669 - * @returns {es.Transaction}
 669+ * @returns {es.TransactionModel}
670670 */
671671 es.DocumentModel.prototype.prepareInsertion = function( offset, data ) {
672672 /**
@@ -719,7 +719,7 @@
720720 return workingData || data;
721721 }
722722
723 - var tx = new es.Transaction(),
 723+ var tx = new es.TransactionModel(),
724724 insertedData = data, // may be cloned and modified
725725 isStructuralLoc,
726726 wrappingElementType;
@@ -823,7 +823,7 @@
824824 *
825825 * @method
826826 * @param {es.Range} range
827 - * @returns {es.Transaction}
 827+ * @returns {es.TransactionModel}
828828 */
829829
830830 es.DocumentModel.prototype.prepareRemoval = function( range ) {
@@ -857,7 +857,7 @@
858858 return true;
859859 }
860860
861 - var tx = new es.Transaction(), selectedNodes, selectedNode, startNode, endNode, i;
 861+ var tx = new es.TransactionModel(), selectedNodes, selectedNode, startNode, endNode, i;
862862 range.normalize();
863863 if ( range.start === range.end ) {
864864 // Empty range, nothing to do
@@ -920,10 +920,10 @@
921921 * Generates a transaction which annotates content within a given range.
922922 *
923923 * @method
924 - * @returns {es.Transaction}
 924+ * @returns {es.TransactionModel}
925925 */
926926 es.DocumentModel.prototype.prepareContentAnnotation = function( range, method, annotation ) {
927 - var tx = new es.Transaction();
 927+ var tx = new es.TransactionModel();
928928 range.normalize();
929929 if ( annotation.hash === undefined ) {
930930 annotation.hash = es.DocumentModel.getAnnotationHash( annotation );
@@ -983,10 +983,10 @@
984984 * Generates a transaction which changes attributes on an element at a given offset.
985985 *
986986 * @method
987 - * @returns {es.Transaction}
 987+ * @returns {es.TransactionModel}
988988 */
989989 es.DocumentModel.prototype.prepareElementAttributeChange = function( offset, method, key, value ) {
990 - var tx = new es.Transaction();
 990+ var tx = new es.TransactionModel();
991991 if ( offset ) {
992992 tx.pushRetain( offset );
993993 }
@@ -1008,7 +1008,7 @@
10091009 * Applies a transaction to the content data.
10101010 *
10111011 * @method
1012 - * @param {es.Transaction}
 1012+ * @param {es.TransactionModel}
10131013 */
10141014 es.DocumentModel.prototype.commit = function( transaction ) {
10151015 es.TransactionProcessor.commit( this, transaction );
@@ -1018,7 +1018,7 @@
10191019 * Reverses a transaction's effects on the content data.
10201020 *
10211021 * @method
1022 - * @param {es.Transaction}
 1022+ * @param {es.TransactionModel}
10231023 */
10241024 es.DocumentModel.prototype.rollback = function( transaction ) {
10251025 es.TransactionProcessor.rollback( this, transaction );
Index: trunk/extensions/VisualEditor/modules/es/models/es.TransactionModel.js
@@ -0,0 +1,150 @@
 2+/**
 3+ * Creates an es.TransactionModel object.
 4+ *
 5+ * @class
 6+ * @constructor
 7+ * @param {Object[]} operations List of operations
 8+ */
 9+es.TransactionModel = function( operations ) {
 10+ this.operations = es.isArray( operations ) ? operations : [];
 11+ this.lengthDiff = 0;
 12+};
 13+
 14+/* Methods */
 15+
 16+/**
 17+ * Gets a list of all operations.
 18+ *
 19+ * @method
 20+ * @returns {Object[]} List of operations
 21+ */
 22+es.TransactionModel.prototype.getOperations = function() {
 23+ return this.operations;
 24+};
 25+
 26+/**
 27+ * Gets the difference in content length this transaction will cause if applied.
 28+ *
 29+ * @method
 30+ * @returns {Integer} Difference in content length
 31+ */
 32+es.TransactionModel.prototype.getLengthDiff = function() {
 33+ return this.lengthDiff;
 34+};
 35+
 36+/**
 37+ * Merges consecutive operations of the same type.
 38+ *
 39+ * @method
 40+ */
 41+es.TransactionModel.prototype.optimize = function() {
 42+ for ( var i = 0; i < this.operations.length - 1; i++ ) {
 43+ var a = this.operations[i];
 44+ var b = this.operations[i + 1];
 45+ if ( a.type === b.type ) {
 46+ switch ( a.type ) {
 47+ case 'retain':
 48+ a.length += b.length;
 49+ this.operations.splice( i + 1, 1 );
 50+ i--;
 51+ break;
 52+ case 'insert':
 53+ case 'remove':
 54+ a.data = a.data.concat( b.data );
 55+ this.operations.splice( i + 1, 1 );
 56+ i--;
 57+ break;
 58+ }
 59+ }
 60+ }
 61+};
 62+
 63+/**
 64+ * Adds a retain operation.
 65+ *
 66+ * @method
 67+ * @param {Integer} length Length of content data to retain
 68+ */
 69+es.TransactionModel.prototype.pushRetain = function( length ) {
 70+ this.operations.push( {
 71+ 'type': 'retain',
 72+ 'length': length
 73+ } );
 74+};
 75+
 76+/**
 77+ * Adds an insertion operation.
 78+ *
 79+ * @method
 80+ * @param {Array} data Data to retain
 81+ */
 82+es.TransactionModel.prototype.pushInsert = function( data ) {
 83+ this.operations.push( {
 84+ 'type': 'insert',
 85+ 'data': data
 86+ } );
 87+ this.lengthDiff += data.length;
 88+};
 89+
 90+/**
 91+ * Adds a removal operation.
 92+ *
 93+ * @method
 94+ * @param {Array} data Data to remove
 95+ */
 96+es.TransactionModel.prototype.pushRemove = function( data ) {
 97+ this.operations.push( {
 98+ 'type': 'remove',
 99+ 'data': data
 100+ } );
 101+ this.lengthDiff -= data.length;
 102+};
 103+
 104+/**
 105+ * Adds an element attribute change operation.
 106+ *
 107+ * @method
 108+ * @param {String} method Method to use, either "set" or "clear"
 109+ * @param {String} key Name of attribute to change
 110+ * @param {Mixed} value Value to set attribute to, or value of attribute being cleared
 111+ */
 112+es.TransactionModel.prototype.pushChangeElementAttribute = function( method, key, value ) {
 113+ this.operations.push( {
 114+ 'type': 'attribute',
 115+ 'method': method,
 116+ 'key': key,
 117+ 'value': value
 118+ } );
 119+};
 120+
 121+/**
 122+ * Adds a start annotating operation.
 123+ *
 124+ * @method
 125+ * @param {String} method Method to use, either "set" or "clear"
 126+ * @param {Object} annotation Annotation object to start setting or clearing from content data
 127+ */
 128+es.TransactionModel.prototype.pushStartAnnotating = function( method, annotation ) {
 129+ this.operations.push( {
 130+ 'type': 'annotate',
 131+ 'method': method,
 132+ 'bias': 'start',
 133+ 'annotation': annotation
 134+ } );
 135+};
 136+
 137+/**
 138+ * Adds a stop annotating operation.
 139+ *
 140+ * @method
 141+ * @param {String} method Method to use, either "set" or "clear"
 142+ * @param {Object} annotation Annotation object to stop setting or clearing from content data
 143+ */
 144+es.TransactionModel.prototype.pushStopAnnotating = function( method, annotation ) {
 145+ this.operations.push( {
 146+ 'type': 'annotate',
 147+ 'method': method,
 148+ 'bias': 'stop',
 149+ 'annotation': annotation
 150+ } );
 151+};
Property changes on: trunk/extensions/VisualEditor/modules/es/models/es.TransactionModel.js
___________________________________________________________________
Added: svn:eol-style
1152 + native
Property changes on: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js
___________________________________________________________________
Deleted: svn:eol-style
2153 - native

Status & tagging log