r99144 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99143‎ | r99144 | r99145 >
Date:21:32, 6 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added es.Transaction and modified es.DocumentModel.[commit|retain] to assume transaction is an array of operations, not an object with an operations property.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/es.Transaction.js (added) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -580,7 +580,11 @@
581581 es.DocumentModel.prototype.prepareRemoval = function( range ) {
582582 /*
583583 * if ( The range spans structural elements ) {
584 - * //
 584+ * if ( The range partially overlaps structural elements ) {
 585+ * Add insertions to replace removed openings and closing to overlapped elements
 586+ * } else {
 587+ * Removing entire structural elements is OK, do nothing
 588+ * }
585589 * } else {
586590 * Removing only content is OK, do nothing
587591 * }
@@ -620,12 +624,12 @@
621625 'set': [],
622626 'clear': []
623627 };
624 - for ( var i = 0, length = this.operations.length; i < length; i++ ) {
625 - var op = this.operations[i];
626 - if ( op.type in this.operations ) {
627 - this.operations[op.type].commit.call( state, op );
 628+ for ( var i = 0, length = transaction.length; i < length; i++ ) {
 629+ var operation = transaction[i];
 630+ if ( operation.type in this.operations ) {
 631+ this.operations[operation.type].commit.call( state, operation );
628632 } else {
629 - throw 'Invalid operation error. Operation type is not supported: ' + op.type;
 633+ throw 'Invalid operation error. Operation type is not supported: ' + operation.type;
630634 }
631635 }
632636 };
@@ -643,12 +647,12 @@
644648 'set': [],
645649 'clear': []
646650 };
647 - for ( var i = 0, length = this.operations.length; i < length; i++ ) {
648 - var op = this.operations[i];
649 - if ( op.type in this.operations ) {
650 - this.operations[op.type].rollback.call( state, op );
 651+ for ( var i = 0, length = transaction.length; i < length; i++ ) {
 652+ var operation = transaction[i];
 653+ if ( operation.type in this.operations ) {
 654+ this.operations[operation.type].rollback.call( state, operation );
651655 } else {
652 - throw 'Invalid operation error. Operation type is not supported: ' + op.type;
 656+ throw 'Invalid operation error. Operation type is not supported: ' + operation.type;
653657 }
654658 }
655659 };
Index: trunk/parsers/wikidom/lib/hype/es.Transaction.js
@@ -0,0 +1,87 @@
 2+/**
 3+ * Creates an es.Transaction object.
 4+ *
 5+ * @class
 6+ * @extends {Array}
 7+ * @constructor
 8+ */
 9+es.Transaction = function() {
 10+ return $.extend( [], this );
 11+};
 12+
 13+/* Methods */
 14+
 15+es.Transaction.prototype.pushRetain( length ) {
 16+ this.push( {
 17+ 'type': 'retain',
 18+ 'length': length
 19+ } );
 20+};
 21+
 22+es.Transaction.prototype.pushInsert( content ) {
 23+ this.push( {
 24+ 'type': 'insert',
 25+ 'data': data
 26+ } );
 27+};
 28+
 29+es.Transaction.prototype.pushRemove( data ) {
 30+ this.push( {
 31+ 'type': 'remove',
 32+ 'data': data
 33+ } );
 34+};
 35+
 36+es.Transaction.prototype.pushSetElementAttribute( key, value ) {
 37+ this.push( {
 38+ 'type': 'attribute',
 39+ 'method': 'set',
 40+ 'key': key,
 41+ 'value': value
 42+ } );
 43+};
 44+
 45+es.Transaction.prototype.pushClearElementAttribute( key, value ) {
 46+ this.push( {
 47+ 'type': 'attribute',
 48+ 'method': 'clear',
 49+ 'key': key,
 50+ 'value': value
 51+ } );
 52+};
 53+
 54+es.Transaction.prototype.pushStartSettingAnnotation( annotation ) {
 55+ this.push( {
 56+ 'type': 'annotate',
 57+ 'method': 'set',
 58+ 'bias': 'start',
 59+ 'annotation': annotation
 60+ } );
 61+};
 62+
 63+es.Transaction.prototype.pushStopSettingAnnotation( annotation ) {
 64+ this.push( {
 65+ 'type': 'annotate',
 66+ 'method': 'set',
 67+ 'bias': 'stop',
 68+ 'annotation': annotation
 69+ } );
 70+};
 71+
 72+es.Transaction.prototype.pushStartClearingAnnotation( annotation ) {
 73+ this.push( {
 74+ 'type': 'annotate',
 75+ 'method': 'clear',
 76+ 'bias': 'start',
 77+ 'annotation': annotation
 78+ } );
 79+};
 80+
 81+es.Transaction.prototype.pushStopClearingAnnotation( annotation ) {
 82+ this.push( {
 83+ 'type': 'annotate',
 84+ 'method': 'clear',
 85+ 'bias': 'stop',
 86+ 'annotation': annotation
 87+ } );
 88+};

Status & tagging log