Index: trunk/parsers/wikidom/lib/es/es.Transaction.js |
— | — | @@ -4,6 +4,25 @@ |
5 | 5 | * Transactions contain a series of operations, such as retain, insert, remove, start and end. Each |
6 | 6 | * operation describes a step that must be taken to construct a new version of a content object. |
7 | 7 | * |
| 8 | + * @example |
| 9 | + * // Given the following content... |
| 10 | + * var content = es.Content.newFromText( 'abc' ); |
| 11 | + * |
| 12 | + * // Build transaction |
| 13 | + * var tx = new es.Transaction(); |
| 14 | + * tx.add( 'retain', 1 ); |
| 15 | + * tx.add( 'remove', content.getData( new es.Range( 1, 2 ) ) ); |
| 16 | + * tx.add( 'insert', es.Content.newFromText( 'B' ) ); |
| 17 | + * tx.add( 'retain', 1 ); |
| 18 | + * |
| 19 | + * // Commit transaction to content |
| 20 | + * var committed = tx.commit( content ); |
| 21 | + * console.log( committed.getText() ); // Logs "aBc" |
| 22 | + * |
| 23 | + * // Apply transaction to content |
| 24 | + * var rolledback = tx.rollback( content ); |
| 25 | + * console.log( rolledback.getText() ); // Logs "abc" |
| 26 | + * |
8 | 27 | * @class |
9 | 28 | * @constructor |
10 | 29 | * @param content {es.Content} Content to operate on |