Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -498,3 +498,37 @@ |
499 | 499 | 'prepareInsertion completes opening elements in inserted content' |
500 | 500 | ); |
501 | 501 | } ); |
| 502 | + |
| 503 | +test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 2, function() { |
| 504 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 505 | + |
| 506 | + var tx = documentModel.prepareInsertion( 4, ['d'] ); |
| 507 | + documentModel.commit( tx ); |
| 508 | + |
| 509 | + deepEqual( |
| 510 | + documentModel.getData( new es.Range( 0, 6 ) ), |
| 511 | + [ |
| 512 | + { 'type': 'paragraph' }, |
| 513 | + 'a', |
| 514 | + ['b', { 'type': 'bold', 'hash': '#bold' }], |
| 515 | + ['c', { 'type': 'italic', 'hash': '#italic' }], |
| 516 | + 'd', |
| 517 | + { 'type': '/paragraph' } |
| 518 | + ], |
| 519 | + 'commit applies a transaction to the content' |
| 520 | + ); |
| 521 | + |
| 522 | + documentModel.rollback( tx ); |
| 523 | + |
| 524 | + deepEqual( |
| 525 | + documentModel.getData( new es.Range( 0, 5 ) ), |
| 526 | + [ |
| 527 | + { 'type': 'paragraph' }, |
| 528 | + 'a', |
| 529 | + ['b', { 'type': 'bold', 'hash': '#bold' }], |
| 530 | + ['c', { 'type': 'italic', 'hash': '#italic' }], |
| 531 | + { 'type': '/paragraph' } |
| 532 | + ], |
| 533 | + 'rollback reverses the effect of a transaction on the content' |
| 534 | + ); |
| 535 | +} ); |
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -817,8 +817,8 @@ |
818 | 818 | }; |
819 | 819 | for ( var i = 0, length = transaction.length; i < length; i++ ) { |
820 | 820 | var operation = transaction[i]; |
821 | | - if ( operation.type in this.operations ) { |
822 | | - this.operations[operation.type].commit.call( state, operation ); |
| 821 | + if ( operation.type in es.DocumentModel.operations ) { |
| 822 | + es.DocumentModel.operations[operation.type].commit.call( state, operation ); |
823 | 823 | } else { |
824 | 824 | throw 'Invalid operation error. Operation type is not supported: ' + operation.type; |
825 | 825 | } |
— | — | @@ -842,8 +842,8 @@ |
843 | 843 | }; |
844 | 844 | for ( var i = 0, length = transaction.length; i < length; i++ ) { |
845 | 845 | var operation = transaction[i]; |
846 | | - if ( operation.type in this.operations ) { |
847 | | - this.operations[operation.type].rollback.call( state, operation ); |
| 846 | + if ( operation.type in es.DocumentModel.operations ) { |
| 847 | + es.DocumentModel.operations[operation.type].rollback.call( state, operation ); |
848 | 848 | } else { |
849 | 849 | throw 'Invalid operation error. Operation type is not supported: ' + operation.type; |
850 | 850 | } |