8
0
Просмотр исходного кода

Transaction rename to Batch. Document.createTransaction renamed to Document.batch.

Szymon Cofalik 10 лет назад
Родитель
Сommit
a9451ca4e0

+ 7 - 7
packages/ckeditor5-utils/src/document/transaction.js

@@ -5,17 +5,17 @@
 
 'use strict';
 
-// All deltas need to be loaded so they can register themselves as transaction methods.
+// All deltas need to be loaded so they can register themselves as Batch methods.
 //
-// To solve circular dependencies (deltas need to require transaction class), transaction class body is moved
-// to document/delta/transaction-base.
+// To solve circular dependencies (deltas need to require Batch class), Batch class body is moved
+// to document/delta/batch-base.
 CKEDITOR.define( [
-	'document/delta/transaction-base',
+	'document/delta/batch-base',
 	'document/delta/insertdelta',
 	'document/delta/removedelta',
 	'document/delta/changedelta',
 	'document/delta/splitdelta',
 	'document/delta/mergedelta'
-], ( Transaction ) => {
-	return Transaction;
-} );
+], ( Batch ) => {
+	return Batch;
+} );

+ 123 - 0
packages/ckeditor5-utils/src/document/delta/batch-base.js

@@ -0,0 +1,123 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+CKEDITOR.define( [ 'ckeditorerror' ], ( CKEditorError ) => {
+	/**
+	 * The Batch class groups document changes (deltas). All deltas grouped in a single Batch can be
+	 * reverted together, so you can think about the Batch as a single undo step. If you want to extend one
+	 * undo step you can call another method on the same Batch object. If you want to create a separate undo step
+	 * you can create a new Batch.
+	 *
+	 * For example to create two separate undo steps you can call:
+	 *
+	 *		doc.batch().insert( firstPosition, 'foo' );
+	 *		doc.batch().insert( secondPosition, 'bar' );
+	 *
+	 * To create a single undo step:
+	 *
+	 *		const batch = doc.batch();
+	 *		batch.insert( firstPosition, 'foo' );
+	 *		batch.insert( secondPosition, 'bar' );
+	 *
+	 * Note that all document modification methods (insert, remove, split, etc.) are chainable so you can shorten code to:
+	 *
+	 *		doc.batch().insert( firstPosition, 'foo' ).insert( secondPosition, 'bar' );
+	 *
+	 * @class document.Batch
+	 */
+	class Batch {
+		/**
+		 * Creates Batch instance. Not recommended to use directly, use {@link document.Document#batch} instead.
+		 *
+		 * @constructor
+		 * @param {document.Document} doc Document which this Batch changes.
+		 */
+		constructor( doc ) {
+			/**
+			 * Document which this Batch changes.
+			 *
+			 * @readonly
+			 * @type {document.Document}
+			 */
+			this.doc = doc;
+
+			/**
+			 * Array of deltas which compose Batch.
+			 *
+			 * @readonly
+			 * @type {Array.<document.delta.Delta>}
+			 */
+			this.deltas = [];
+		}
+
+		/**
+		 * Adds delta to the Batch instance. All modification methods (insert, remove, split, etc.) use this method
+		 * to add created deltas.
+		 *
+		 * @param {document.delta.Delta} delta Delta to add.
+		 * @return {document.delta.Delta} Added delta.
+		 */
+		addDelta( delta ) {
+			delta.batch = this;
+			this.deltas.push( delta );
+
+			return delta;
+		}
+
+		/**
+		 * Static method to register Batch methods. To make code scalable Batch do not have modification
+		 * methods built in. They can be registered using this method.
+		 *
+		 * This method checks if there is no naming collision and throws `batch-register-taken` if the method name
+		 * is already taken.
+		 *
+		 * Besides that no magic happens here, the method is added to the `Batch` class prototype.
+		 *
+		 * For example:
+		 *
+		 *		Batch.register( 'insert', function( position, nodes ) {
+		 *			// You can use a class inherit from Delta if that class should handle OT in the special way.
+		 *			const delta = new Delta();
+		 *
+		 * 			// Create operations which should be components of this delta.
+		 *			const operation = new InsertOperation( position, nodes, this.doc.version );
+		 *
+		 *			// Remember to apply every operation, no magic, you need to do it manually.
+		 *			this.doc.applyOperation( operation );
+		 *
+		 *			// Add operation to the delta.
+		 *			delta.addOperation( operation );
+		 *
+		 *			// Add delta to the Batch instance.
+		 *			this.addDelta( delta );
+		 *
+		 * 			// Make this method chainable.
+		 * 			return this;
+		 *		} );
+		 *
+		 * @param {String} name Method name.
+		 * @param {Function} creator Method body.
+		 */
+		static register( name, creator ) {
+			if ( Batch.prototype[ name ] ) {
+				/**
+				 * This batch method name is already taken.
+				 *
+				 * @error batch-register-taken
+				 * @param {String} name
+				 */
+				throw new CKEditorError(
+					'batch-register-taken: This batch method name is already taken.',
+					{ name: name } );
+			}
+
+			Batch.prototype[ name ] = creator;
+		}
+	}
+
+	return Batch;
+} );

+ 10 - 10
packages/ckeditor5-utils/src/document/delta/changedelta.js

@@ -15,8 +15,8 @@ CKEDITOR.define( [
 	'document/element'
 ], ( Delta, register, ChangeOperation, Position, Range, Attribute, Element ) => {
 	/**
-	 * To provide specific OT behavior and better collisions solving, change methods ({@link document.Transaction#setAttr}
-	 * and {@link document.Transaction#removeAttr}) use `ChangeDelta` class which inherits from the `Delta` class and may
+	 * To provide specific OT behavior and better collisions solving, change methods ({@link document.Batch#setAttr}
+	 * and {@link document.Batch#removeAttr}) use `ChangeDelta` class which inherits from the `Delta` class and may
 	 * overwrite some methods.
 	 *
 	 * @class document.delta.ChangeDelta
@@ -28,9 +28,9 @@ CKEDITOR.define( [
 	 *
 	 * @chainable
 	 * @method setAttr
-	 * @memberOf document.Transaction
+	 * @memberOf document.Batch
 	 * @param {String} key Attribute key.
-	 * @param {Mixed} value Attribute new value.
+	 * @param {*} value Attribute new value.
 	 * @param {document.Node|document.Range} nodeOrRange Node or range on which the attribute will be set.
 	 */
 	register( 'setAttr', function( key, value, nodeOrRange ) {
@@ -44,7 +44,7 @@ CKEDITOR.define( [
 	 *
 	 * @chainable
 	 * @method removeAttr
-	 * @memberOf document.Transaction
+	 * @memberOf document.Batch
 	 * @param {String} key Attribute key.
 	 * @param {document.Node|document.Range} nodeOrRange Node or range on which the attribute will be removed.
 	 */
@@ -54,16 +54,16 @@ CKEDITOR.define( [
 		return this;
 	} );
 
-	function change( transaction, key, value, nodeOrRange ) {
+	function change( batch, key, value, nodeOrRange ) {
 		const delta = new ChangeDelta();
 
 		if ( nodeOrRange instanceof Range ) {
-			changeRange( transaction.doc, delta, key, value, nodeOrRange );
+			changeRange( batch.doc, delta, key, value, nodeOrRange );
 		} else {
-			changeNode( transaction.doc, delta, key, value, nodeOrRange );
+			changeNode( batch.doc, delta, key, value, nodeOrRange );
 		}
 
-		transaction.addDelta( delta );
+		batch.addDelta( delta );
 	}
 
 	function changeNode( doc, delta, key, value, node ) {
@@ -152,4 +152,4 @@ CKEDITOR.define( [
 	}
 
 	return ChangeDelta;
-} );
+} );

+ 6 - 6
packages/ckeditor5-utils/src/document/delta/delta.js

@@ -12,7 +12,7 @@ CKEDITOR.define( [], () => {
 	 * Delta is a single, from the user action point of view, change in the editable document, like insert, split or
 	 * rename element. Delta is composed of operations, which are unit changes needed to be done to execute user action.
 	 *
-	 * Multiple deltas are grouped into a single {@link document.Transaction}.
+	 * Multiple deltas are grouped into a single {@link document.Batch}.
 	 *
 	 * @class document.delta.Delta
 	 */
@@ -24,13 +24,13 @@ CKEDITOR.define( [], () => {
 		 */
 		constructor() {
 			/**
-			 * {@link document.Transaction} which delta is a part of. This property is null by default and set by the
-			 * {@link Document.Transaction#addDelta} method.
+			 * {@link document.Batch} which delta is a part of. This property is null by default and set by the
+			 * {@link Document.Batch#addDelta} method.
 			 *
 			 * @readonly
-			 * @type {document.Transaction}
+			 * @type {document.Batch}
 			 */
-			this.transaction = null;
+			this.batch = null;
 
 			/**
 			 * Array of operations which compose delta.
@@ -55,4 +55,4 @@ CKEDITOR.define( [], () => {
 	}
 
 	return Delta;
-} );
+} );

+ 3 - 3
packages/ckeditor5-utils/src/document/delta/insertdelta.js

@@ -11,7 +11,7 @@ CKEDITOR.define( [
 	'document/operation/insertoperation'
 ], ( Delta, register, InsertOperation ) => {
 	/**
-	 * To provide specific OT behavior and better collisions solving, the {@link document.Transaction#insert} method
+	 * To provide specific OT behavior and better collisions solving, the {@link document.Batch#insert} method
 	 * uses the `InsertDelta` class which inherits from the `Delta` class and may overwrite some methods.
 	 *
 	 * @class document.delta.InsertDelta
@@ -22,7 +22,7 @@ CKEDITOR.define( [
 	 * Inserts a node or nodes at the given position.
 	 *
 	 * @chainable
-	 * @memberOf document.Transaction
+	 * @memberOf document.Batch
 	 * @method insert
 	 * @param {document.Position} position Position of insertion.
 	 * @param {document.Node|document.Text|document.NodeList|String|Iterable} nodes The list of nodes to be inserted.
@@ -41,4 +41,4 @@ CKEDITOR.define( [
 	} );
 
 	return InsertDelta;
-} );
+} );

+ 8 - 8
packages/ckeditor5-utils/src/document/delta/mergedelta.js

@@ -15,7 +15,7 @@ CKEDITOR.define( [
 	'ckeditorerror'
 ], ( Delta, register, Position, Element, RemoveOperation, MoveOperation, CKEditorError ) => {
 	/**
-	 * To provide specific OT behavior and better collisions solving, {@link document.Transaction#merge} method
+	 * To provide specific OT behavior and better collisions solving, {@link document.Batch#merge} method
 	 * uses the `MergeDelta` class which inherits from the `Delta` class and may overwrite some methods.
 	 *
 	 * @class document.delta.MergeDelta
@@ -25,12 +25,12 @@ CKEDITOR.define( [
 	/**
 	 * Merges two siblings at the given position.
 	 *
-	 * Node before and after the position have to be an element. Otherwise `transaction-merge-no-element-before` or
-	 * `transaction-merge-no-element-after` error will be thrown.
+	 * Node before and after the position have to be an element. Otherwise `batch-merge-no-element-before` or
+	 * `batch-merge-no-element-after` error will be thrown.
 	 *
 	 * @chainable
 	 * @method merge
-	 * @memberOf document.Transaction
+	 * @memberOf document.Batch
 	 * @param {document.Position} position Position of merge.
 	 */
 	register( 'merge', function( position ) {
@@ -42,20 +42,20 @@ CKEDITOR.define( [
 			/**
 			 * Node before merge position must be an element.
 			 *
-			 * @error transaction-merge-no-element-before
+			 * @error batch-merge-no-element-before
 			 */
 			throw new CKEditorError(
-				'transaction-merge-no-element-before: Node before merge position must be an element.' );
+				'batch-merge-no-element-before: Node before merge position must be an element.' );
 		}
 
 		if ( !( nodeAfter instanceof Element ) ) {
 			/**
 			 * Node after merge position must be an element.
 			 *
-			 * @error transaction-merge-no-element-after
+			 * @error batch-merge-no-element-after
 			 */
 			throw new CKEditorError(
-				'transaction-merge-no-element-after: Node after merge position must be an element.' );
+				'batch-merge-no-element-after: Node after merge position must be an element.' );
 		}
 
 		const positionAfter = Position.createFromParentAndOffset( nodeAfter, 0 );

+ 4 - 4
packages/ckeditor5-utils/src/document/delta/register.js

@@ -8,7 +8,7 @@
 // Register method exposed for deltas, which needs only this method, to make code simpler, more beautiful and, first of
 // all, to solve circular dependencies.
 CKEDITOR.define( [
-	'document/delta/transaction-base'
-], ( Transaction ) => {
-	return Transaction.register;
-} );
+	'document/delta/batch-base'
+], ( Batch ) => {
+	return Batch.register;
+} );

+ 3 - 3
packages/ckeditor5-utils/src/document/delta/removedelta.js

@@ -11,7 +11,7 @@ CKEDITOR.define( [
 	'document/operation/removeoperation'
 ], ( Delta, register, RemoveOperation ) => {
 	/**
-	 * To provide specific OT behavior and better collisions solving, {@link document.Transaction#remove} method
+	 * To provide specific OT behavior and better collisions solving, {@link document.Batch#remove} method
 	 * uses the `RemoveDelta` class which inherits from the `Delta` class and may overwrite some methods.
 	 *
 	 * @class document.delta.RemoveDelta
@@ -23,7 +23,7 @@ CKEDITOR.define( [
 	 *
 	 * @chainable
 	 * @method remove
-	 * @memberOf document.Transaction
+	 * @memberOf document.Batch
 	 * @param {document.Position} position Position before the first node to remove.
 	 * @param {Number} howMany How many nodes to remove.
 	 */
@@ -44,4 +44,4 @@ CKEDITOR.define( [
 	} );
 
 	return RemoveDelta;
-} );
+} );

+ 5 - 5
packages/ckeditor5-utils/src/document/delta/splitdelta.js

@@ -15,7 +15,7 @@ CKEDITOR.define( [
 	'ckeditorerror'
 ], ( Delta, register, Position, Element, InsertOperation, MoveOperation, CKEditorError ) => {
 	/**
-	 * To provide specific OT behavior and better collisions solving, the {@link document.Transaction#split} method
+	 * To provide specific OT behavior and better collisions solving, the {@link document.Batch#split} method
 	 * uses `SplitDelta` class which inherits from the `Delta` class and may overwrite some methods.
 	 *
 	 * @class document.delta.SplitDelta
@@ -25,12 +25,12 @@ CKEDITOR.define( [
 	/**
 	 * Splits a node at the given position.
 	 *
-	 * This cannot be a position inside the root element. The `transaction-split-root` error will be thrown if
+	 * This cannot be a position inside the root element. The `batch-split-root` error will be thrown if
 	 * you try to split the root element.
 	 *
 	 * @chainable
 	 * @method split
-	 * @memberOf document.Transaction
+	 * @memberOf document.Batch
 	 * @param {document.Position} position Position of split.
 	 */
 	register( 'split', function( position ) {
@@ -41,9 +41,9 @@ CKEDITOR.define( [
 			/**
 			 * Root element can not be split.
 			 *
-			 * @error transaction-split-root
+			 * @error batch-split-root
 			 */
-			throw new CKEditorError( 'transaction-split-root: Root element can not be split.' );
+			throw new CKEditorError( 'batch-split-root: Root element can not be split.' );
 		}
 
 		const copy = new Element( splitElement.name, splitElement.getAttrs() );

+ 0 - 124
packages/ckeditor5-utils/src/document/delta/transaction-base.js

@@ -1,124 +0,0 @@
-/**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-CKEDITOR.define( [ 'ckeditorerror' ], ( CKEditorError ) => {
-	/**
-	 * The transaction class groups document changes (deltas). All deltas grouped in a single transactions can be
-	 * reverted together, so you can think about the transaction as a single undo step. If you want to extend one
-	 * undo step you can call another method on the same transaction object. If you want to create a separate undo step
-	 * you can create a new transaction.
-	 *
-	 * For example to create two separate undo steps you can call:
-	 *
-	 *		doc.createTransaction().insert( firstPosition, 'foo' );
-	 *		doc.createTransaction().insert( secondPosition, 'bar' );
-	 *
-	 * To create a single undo step:
-	 *
-	 *		const transaction = doc.createTransaction()
-	 *		transaction.insert( firstPosition, 'foo' );
-	 *		transaction.insert( secontPosition, 'bar' );
-	 *
-	 * Note that all document modification methods (insert, remove, split, etc.) are chainable so you can shorten code to:
-	 *
-	 *		doc.createTransaction().insert( firstPosition, 'foo' ).insert( secontPosition, 'bar' );
-	 *
-	 * @class document.Transaction
-	 */
-	class Transaction {
-		/**
-		 * Creates transaction instance. Not recommended to use directly, use {@link document.Document#createTransaction}
-		 * instead.
-		 *
-		 * @constructor
-		 * @param {document.Document} doc Document which this transaction changes.
-		 */
-		constructor( doc ) {
-			/**
-			 * Document which this transaction changes.
-			 *
-			 * @readonly
-			 * @type {document.Document}
-			 */
-			this.doc = doc;
-
-			/**
-			 * Array of deltas which compose transaction.
-			 *
-			 * @readonly
-			 * @type {document.delta.Delta[]}
-			 */
-			this.deltas = [];
-		}
-
-		/**
-		 * Adds delta to the transaction instance. All modification methods (insert, remove, split, etc.) use this method
-		 * to add created deltas.
-		 *
-		 * @param {document.delta.Delta} delta Delta to add.
-		 * @return {document.delta.Delta} Added delta.
-		 */
-		addDelta( delta ) {
-			delta.transaction = this;
-			this.deltas.push( delta );
-
-			return delta;
-		}
-
-		/**
-		 * Static method to register transaction methods. To make code scalable transaction do not have modification
-		 * methods built in. They can be registered using this method.
-		 *
-		 * This method checks if there is no naming collision and throw `transaction-register-taken` if the method name
-		 * is already taken.
-		 *
-		 * Beside that no magic happens here, the method is added to the `Transaction` class prototype.
-		 *
-		 * For example:
-		 *
-		 *		Transaction.register( 'insert', function( position, nodes ) {
-		 *			// You can use a class inherit from Delta if that class should handle OT in the special way.
-		 *			const delta = new Delta();
-		 *
-		 * 			// Create operations which should be components of this delta.
-		 *			const operation = new InsertOperation( position, nodes, this.doc.version );
-		 *
-		 *			// Remember to apply every operation, no magic, you need to do it manually.
-		 *			this.doc.applyOperation( operation );
-		 *
-		 *			// Add operation to the delta.
-		 *			delta.addOperation( operation );
-		 *
-		 *			// Add delta to the transaction instance.
-		 *			this.addDelta( delta );
-		 *
-		 * 			// Make this method chainable.
-		 * 			return this;
-		 *		} );
-		 *
-		 * @param {String} name Method name.
-		 * @param {Fuction} creator Method body.
-		 */
-		static register( name, creator ) {
-			if ( Transaction.prototype[ name ] ) {
-				/**
-				 * This transaction method is already taken.
-				 *
-				 * @error transaction-register-taken
-				 * @param {String} name
-				 */
-				throw new CKEditorError(
-					'transaction-register-taken: This transaction method is already taken.',
-					{ name: name } );
-			}
-
-			Transaction.prototype[ name ] = creator;
-		}
-	}
-
-	return Transaction;
-} );

+ 15 - 15
packages/ckeditor5-utils/src/document/document.js

@@ -8,11 +8,11 @@
 CKEDITOR.define( [
 	'document/element',
 	'document/rootelement',
-	'document/transaction',
+	'document/batch',
 	'emittermixin',
 	'utils',
 	'ckeditorerror'
-], ( Element, RootElement, Transaction, EmitterMixin, utils, CKEditorError ) => {
+], ( Element, RootElement, Batch, EmitterMixin, utils, CKEditorError ) => {
 	const graveyardSymbol = Symbol( 'graveyard' );
 
 	/**
@@ -20,11 +20,11 @@ CKEDITOR.define( [
 	 * for example if the editor have multiple editable areas, each area will be represented by the separate root.
 	 *
 	 * All changes in the document are done by {@link document.operation.Operation operations}. To create operations in
-	 * the simple way use use the {@link document.Transaction transaction} API, for example:
+	 * the simple way use use the {@link document.Batch} API, for example:
 	 *
-	 *		document.createTransaction().insert( position, nodes ).split( otherPosition );
+	 *		document.batch().insert( position, nodes ).split( otherPosition );
 	 *
-	 * @see #createTransaction
+	 * @see #batch
 	 *
 	 * @class document.Document
 	 */
@@ -71,7 +71,7 @@ CKEDITOR.define( [
 		/**
 		 * This is the entry point for all document changes. All changes on the document are done using
 		 * {@link document.operation.Operation operations}. To create operations in the simple way use the
-		 * {@link document.Transaction} API available via {@link #createTransaction} method.
+		 * {@link document.Batch} API available via {@link #batch} method.
 		 *
 		 * @param {document.operation.Operation} operation Operation to be applied.
 		 */
@@ -96,6 +96,15 @@ CKEDITOR.define( [
 		}
 
 		/**
+		 * Creates a {@link document.Batch} instance which allows to change the document.
+		 *
+		 * @returns {document.Batch} Batch instance.
+		 */
+		batch() {
+			return new Batch( this );
+		}
+
+		/**
 		 * Creates a new top-level root.
 		 *
 		 * @param {String|Symbol} name Unique root name.
@@ -123,15 +132,6 @@ CKEDITOR.define( [
 		}
 
 		/**
-		 * Creates a {@link document.Transaction} instance which allows to change the document.
-		 *
-		 * @returns {document.Transaction} Transaction instance.
-		 */
-		createTransaction() {
-			return new Transaction( this );
-		}
-
-		/**
 		 * Returns top-level root by it's name.
 		 *
 		 * @param {String|Symbol} name Name of the root to get.

+ 83 - 0
packages/ckeditor5-utils/tests/document/batch.js

@@ -0,0 +1,83 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* bender-tags: document, delta */
+
+'use strict';
+
+const modules = bender.amd.require(
+	'document/batch',
+	'document/delta/delta',
+	'ckeditorerror'
+);
+
+describe( 'Batch', () => {
+	let Batch, Delta, CKEditorError;
+
+	before( () => {
+		Batch = modules[ 'document/batch' ];
+		Delta = modules[ 'document/delta/delta' ];
+		CKEditorError = modules.ckeditorerror;
+	} );
+
+	it( 'should have registered basic methods', () => {
+		const batch = new Batch();
+
+		expect( batch.setAttr ).to.be.a( 'function' );
+		expect( batch.removeAttr ).to.be.a( 'function' );
+	} );
+
+	describe( 'Batch.register', () => {
+		let TestDelta;
+
+		before( () => {
+			TestDelta = class extends Delta {
+				constructor( batch ) {
+					super( batch, [] );
+				}
+			};
+		} );
+
+		afterEach( () => {
+			delete Batch.prototype.foo;
+		} );
+
+		it( 'should register function which return an delta', () => {
+			Batch.register( 'foo', function() {
+				this.addDelta( new TestDelta() );
+			} );
+
+			const batch = new Batch();
+
+			batch.foo();
+
+			expect( batch.deltas.length ).to.equal( 1 );
+			expect( batch.deltas[ 0 ] ).to.be.instanceof( TestDelta );
+		} );
+
+		it( 'should register function which return an multiple deltas', () => {
+			Batch.register( 'foo', function() {
+				this.addDelta( new TestDelta() );
+				this.addDelta( new TestDelta() );
+			} );
+
+			const batch = new Batch();
+
+			batch.foo();
+
+			expect( batch.deltas.length ).to.equal( 2 );
+			expect( batch.deltas[ 0 ] ).to.be.instanceof( TestDelta );
+			expect( batch.deltas[ 1 ] ).to.be.instanceof( TestDelta );
+		} );
+
+		it( 'should throw if one try to register the same batch twice', () => {
+			Batch.register( 'foo', () => {} );
+
+			expect( () => {
+				Batch.register( 'foo', () => {} );
+			} ).to.throw( CKEditorError, /^batch-register-taken/ );
+		} );
+	} );
+} );

+ 39 - 39
packages/ckeditor5-utils/tests/document/deltas/changedelta.js

@@ -12,7 +12,7 @@
 const getIteratorCount = bender.tools.core.getIteratorCount;
 
 const modules = bender.amd.require(
-	'document/transaction',
+	'document/batch',
 	'document/document',
 	'document/text',
 	'document/attribute',
@@ -21,13 +21,13 @@ const modules = bender.amd.require(
 	'document/element',
 	'document/character' );
 
-describe( 'Transaction', () => {
-	let Transaction, Document, Text, Attribute, Range, Position, Element, Character;
+describe( 'Batch', () => {
+	let Batch, Document, Text, Attribute, Range, Position, Element, Character;
 
-	let doc, root, transaction;
+	let doc, root, batch;
 
 	before( () => {
-		Transaction = modules[ 'document/transaction' ];
+		Batch = modules[ 'document/batch' ];
 		Document = modules[ 'document/document' ];
 		Text = modules[ 'document/text' ];
 		Attribute = modules[ 'document/attribute' ];
@@ -40,13 +40,13 @@ describe( 'Transaction', () => {
 	beforeEach( () => {
 		doc = new Document();
 		root = doc.createRoot( 'root' );
-		transaction = doc.createTransaction();
+		batch = doc.batch();
 	} );
 
 	function getOperationsCount() {
 		let count = 0;
 
-		for ( let delta of transaction.deltas ) {
+		for ( let delta of batch.deltas ) {
 			count += getIteratorCount( delta.operations );
 		}
 
@@ -64,62 +64,62 @@ describe( 'Transaction', () => {
 
 		describe( 'setAttr', () => {
 			it( 'should create the attribute on element', () => {
-				transaction.setAttr( 'b', 2, node );
+				batch.setAttr( 'b', 2, node );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( node.getAttr( 'b' ) ).to.equal( 2 );
 			} );
 
 			it( 'should change the attribute of element', () => {
-				transaction.setAttr( 'a', 2, node );
+				batch.setAttr( 'a', 2, node );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( node.getAttr( 'a' ) ).to.equal( 2 );
 			} );
 
 			it( 'should create the attribute on character', () => {
-				transaction.setAttr( 'b', 2, character );
+				batch.setAttr( 'b', 2, character );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( character.getAttr( 'b' ) ).to.equal( 2 );
 			} );
 
 			it( 'should change the attribute of character', () => {
-				transaction.setAttr( 'a', 2, character );
+				batch.setAttr( 'a', 2, character );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( character.getAttr( 'a' ) ).to.equal( 2 );
 			} );
 
 			it( 'should do nothing if the attribute value is the same', () => {
-				transaction.setAttr( 'a', 1, node );
+				batch.setAttr( 'a', 1, node );
 				expect( getOperationsCount() ).to.equal( 0 );
 				expect( node.getAttr( 'a' ) ).to.equal( 1 );
 			} );
 
 			it( 'should be chainable', () => {
-				const chain = transaction.setAttr( 'b', 2, node );
-				expect( chain ).to.equal( transaction );
+				const chain = batch.setAttr( 'b', 2, node );
+				expect( chain ).to.equal( batch );
 			} );
 		} );
 
 		describe( 'removeAttr', () => {
 			it( 'should remove the attribute from element', () => {
-				transaction.removeAttr( 'a', node );
+				batch.removeAttr( 'a', node );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( node.getAttr( 'a' ) ).to.be.null;
 			} );
 
 			it( 'should remove the attribute from character', () => {
-				transaction.removeAttr( 'a', character );
+				batch.removeAttr( 'a', character );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( character.getAttr( 'a' ) ).to.be.null;
 			} );
 
 			it( 'should do nothing if the attribute is not set', () => {
-				transaction.removeAttr( 'b', node );
+				batch.removeAttr( 'b', node );
 				expect( getOperationsCount() ).to.equal( 0 );
 			} );
 
 			it( 'should be chainable', () => {
-				const chain = transaction.removeAttr( 'a', node );
-				expect( chain ).to.equal( transaction );
+				const chain = batch.removeAttr( 'a', node );
+				expect( chain ).to.equal( batch );
 			} );
 		} );
 	} );
@@ -146,7 +146,7 @@ describe( 'Transaction', () => {
 		function getChangesAttrsCount() {
 			let count = 0;
 
-			for ( let delta of transaction.deltas ) {
+			for ( let delta of batch.deltas ) {
 				for ( let operation of delta.operations ) {
 					count += getIteratorCount( operation.range );
 				}
@@ -164,112 +164,112 @@ describe( 'Transaction', () => {
 
 		describe( 'setAttr', () => {
 			it( 'should set the attribute on the range', () => {
-				transaction.setAttr( 'a', 3, getRange( 3, 6 ) );
+				batch.setAttr( 'a', 3, getRange( 3, 6 ) );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( getChangesAttrsCount() ).to.equal( 3 );
 				expect( getCompressedAttrs() ).to.equal( '111333111222---111' );
 			} );
 
 			it( 'should split the operations if parts of the range have different attributes', () => {
-				transaction.setAttr( 'a', 3, getRange( 4, 14 ) );
+				batch.setAttr( 'a', 3, getRange( 4, 14 ) );
 				expect( getOperationsCount() ).to.equal( 4 );
 				expect( getChangesAttrsCount() ).to.equal( 10 );
 				expect( getCompressedAttrs() ).to.equal( '111-3333333333-111' );
 			} );
 
 			it( 'should split the operations if parts of the part of the range have the attribute', () => {
-				transaction.setAttr( 'a', 2, getRange( 4, 14 ) );
+				batch.setAttr( 'a', 2, getRange( 4, 14 ) );
 				expect( getOperationsCount() ).to.equal( 3 );
 				expect( getChangesAttrsCount() ).to.equal( 7 );
 				expect( getCompressedAttrs() ).to.equal( '111-2222222222-111' );
 			} );
 
 			it( 'should strip the range if the beginning have the attribute', () => {
-				transaction.setAttr( 'a', 1, getRange( 1, 5 ) );
+				batch.setAttr( 'a', 1, getRange( 1, 5 ) );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( getChangesAttrsCount() ).to.equal( 2 );
 				expect( getCompressedAttrs() ).to.equal( '11111-111222---111' );
 			} );
 
 			it( 'should strip the range if the ending have the attribute', () => {
-				transaction.setAttr( 'a', 1, getRange( 13, 17 ) );
+				batch.setAttr( 'a', 1, getRange( 13, 17 ) );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( getChangesAttrsCount() ).to.equal( 2 );
 				expect( getCompressedAttrs() ).to.equal( '111---111222-11111' );
 			} );
 
 			it( 'should do nothing if the range has attribute', () => {
-				transaction.setAttr( 'a', 1, getRange( 0, 3 ) );
+				batch.setAttr( 'a', 1, getRange( 0, 3 ) );
 				expect( getOperationsCount() ).to.equal( 0 );
 				expect( getCompressedAttrs() ).to.equal( '111---111222---111' );
 			} );
 
 			it( 'should create a proper operations for the mixed range', () => {
-				transaction.setAttr( 'a', 1, getRange( 0, 18 ) );
+				batch.setAttr( 'a', 1, getRange( 0, 18 ) );
 				expect( getOperationsCount() ).to.equal( 3 );
 				expect( getChangesAttrsCount() ).to.equal( 9 );
 				expect( getCompressedAttrs() ).to.equal( '111111111111111111' );
 			} );
 
 			it( 'should be chainable', () => {
-				const chain = transaction.setAttr( 'a', 3, getRange( 3, 6 ) );
-				expect( chain ).to.equal( transaction );
+				const chain = batch.setAttr( 'a', 3, getRange( 3, 6 ) );
+				expect( chain ).to.equal( batch );
 			} );
 		} );
 
 		describe( 'removeAttr', () => {
 			it( 'should remove the attribute on the range', () => {
-				transaction.removeAttr( 'a', getRange( 0, 2 ) );
+				batch.removeAttr( 'a', getRange( 0, 2 ) );
 				expect( getOperationsCount() ).to.equal( 1 );
 				expect( getChangesAttrsCount() ).to.equal( 2 );
 				expect( getCompressedAttrs() ).to.equal( '--1---111222---111' );
 			} );
 
 			it( 'should split the operations if parts of the range have different attributes', () => {
-				transaction.removeAttr( 'a', getRange( 7, 11 ) );
+				batch.removeAttr( 'a', getRange( 7, 11 ) );
 				expect( getOperationsCount() ).to.equal( 2 );
 				expect( getChangesAttrsCount() ).to.equal( 4 );
 				expect( getCompressedAttrs() ).to.equal( '111---1----2---111' );
 			} );
 
 			it( 'should split the operations if parts of the part of the range have no attribute', () => {
-				transaction.removeAttr( 'a', getRange( 1, 7 ) );
+				batch.removeAttr( 'a', getRange( 1, 7 ) );
 				expect( getOperationsCount() ).to.equal( 2 );
 				expect( getChangesAttrsCount() ).to.equal( 3 );
 				expect( getCompressedAttrs() ).to.equal( '1------11222---111' );
 			} );
 
 			it( 'should strip the range if the beginning have no attribute', () => {
-				transaction.removeAttr( 'a', getRange( 4, 12 ) );
+				batch.removeAttr( 'a', getRange( 4, 12 ) );
 				expect( getOperationsCount() ).to.equal( 2 );
 				expect( getChangesAttrsCount() ).to.equal( 6 );
 				expect( getCompressedAttrs() ).to.equal( '111------------111' );
 			} );
 
 			it( 'should strip the range if the ending have no attribute', () => {
-				transaction.removeAttr( 'a', getRange( 7, 15 ) );
+				batch.removeAttr( 'a', getRange( 7, 15 ) );
 				expect( getOperationsCount() ).to.equal( 2 );
 				expect( getChangesAttrsCount() ).to.equal( 5 );
 				expect( getCompressedAttrs() ).to.equal( '111---1--------111' );
 			} );
 
 			it( 'should do nothing if the range has no attribute', () => {
-				transaction.removeAttr( 'a', getRange( 4, 5 ) );
+				batch.removeAttr( 'a', getRange( 4, 5 ) );
 				expect( getOperationsCount() ).to.equal( 0 );
 				expect( getCompressedAttrs() ).to.equal( '111---111222---111' );
 			} );
 
 			it( 'should create a proper operations for the mixed range', () => {
-				transaction.removeAttr( 'a', getRange( 3, 15 ) );
+				batch.removeAttr( 'a', getRange( 3, 15 ) );
 				expect( getOperationsCount() ).to.equal( 2 );
 				expect( getChangesAttrsCount() ).to.equal( 6 );
 				expect( getCompressedAttrs() ).to.equal( '111------------111' );
 			} );
 
 			it( 'should be chainable', () => {
-				const chain = transaction.removeAttr( 'a', getRange( 0, 2 ) );
-				expect( chain ).to.equal( transaction );
+				const chain = batch.removeAttr( 'a', getRange( 0, 2 ) );
+				expect( chain ).to.equal( batch );
 			} );
 		} );
 	} );
-} );
+} );

+ 2 - 2
packages/ckeditor5-utils/tests/document/deltas/delta.js

@@ -25,7 +25,7 @@ describe( 'Delta', () => {
 		it( 'should create an delta with empty properties', () => {
 			const delta = new Delta();
 
-			expect( delta ).to.have.property( 'transaction' ).that.is.null;
+			expect( delta ).to.have.property( 'batch' ).that.is.null;
 			expect( delta ).to.have.property( 'operations' ).that.a( 'array' ).and.have.length( 0 );
 		} );
 	} );
@@ -64,4 +64,4 @@ describe( 'Delta', () => {
 			expect( count ).to.equal( 3 );
 		} );
 	} );
-} );
+} );

+ 5 - 5
packages/ckeditor5-utils/tests/document/deltas/insertdelta.js

@@ -11,7 +11,7 @@ const modules = bender.amd.require(
 	'document/document',
 	'document/position' );
 
-describe( 'Transaction', () => {
+describe( 'Batch', () => {
 	let Document, Position;
 
 	let doc, root;
@@ -28,7 +28,7 @@ describe( 'Transaction', () => {
 
 	it( 'should insert text', () => {
 		const position = new Position( root, [ 0 ] );
-		doc.createTransaction().insert( position, 'foo' );
+		doc.batch().insert( position, 'foo' );
 
 		expect( root.getChildCount() ).to.equal( 3 );
 		expect( root.getChild( 0 ).character ).to.equal( 'f' );
@@ -38,9 +38,9 @@ describe( 'Transaction', () => {
 
 	it( 'should be chainable', () => {
 		const position = new Position( root, [ 0 ] );
-		const transaction = doc.createTransaction();
+		const batch = doc.batch();
 
-		const chain = transaction.insert( position, 'foo' );
-		expect( chain ).to.equal( transaction );
+		const chain = batch.insert( position, 'foo' );
+		expect( chain ).to.equal( batch );
 	} );
 } );

+ 9 - 9
packages/ckeditor5-utils/tests/document/deltas/mergedelta.js

@@ -18,7 +18,7 @@ const modules = bender.amd.require(
 	'document/attribute',
 	'ckeditorerror' );
 
-describe( 'Transaction', () => {
+describe( 'Batch', () => {
 	let Document, Position, Element, Attribute, CKEditorError;
 
 	let doc, root, p1, p2;
@@ -43,7 +43,7 @@ describe( 'Transaction', () => {
 
 	describe( 'merge', () => {
 		it( 'should merge foo and bar into foobar', () => {
-			doc.createTransaction().merge( new Position( root, [ 1 ] ) );
+			doc.batch().merge( new Position( root, [ 1 ] ) );
 
 			expect( root.getChildCount() ).to.equal( 1 );
 			expect( root.getChild( 0 ).name ).to.equal( 'p' );
@@ -60,21 +60,21 @@ describe( 'Transaction', () => {
 
 		it( 'should throw if there is no element after', () => {
 			expect( () => {
-				doc.createTransaction().merge( new Position( root, [ 2 ] ) );
-			} ).to.throw( CKEditorError, /^transaction-merge-no-element-after/ );
+				doc.batch().merge( new Position( root, [ 2 ] ) );
+			} ).to.throw( CKEditorError, /^batch-merge-no-element-after/ );
 		} );
 
 		it( 'should throw if there is no element before', () => {
 			expect( () => {
-				doc.createTransaction().merge( new Position( root, [ 0, 2 ] ) );
-			} ).to.throw( CKEditorError, /^transaction-merge-no-element-before/ );
+				doc.batch().merge( new Position( root, [ 0, 2 ] ) );
+			} ).to.throw( CKEditorError, /^batch-merge-no-element-before/ );
 		} );
 
 		it( 'should be chainable', () => {
-			const transaction = doc.createTransaction();
+			const batch = doc.batch();
 
-			const chain = transaction.merge( new Position( root, [ 1 ] ) );
-			expect( chain ).to.equal( transaction );
+			const chain = batch.merge( new Position( root, [ 1 ] ) );
+			expect( chain ).to.equal( batch );
 		} );
 	} );
 } );

+ 6 - 6
packages/ckeditor5-utils/tests/document/deltas/removedelta.js

@@ -11,7 +11,7 @@ const modules = bender.amd.require(
 	'document/document',
 	'document/position' );
 
-describe( 'Transaction', () => {
+describe( 'Batch', () => {
 	let Document, Position;
 
 	let doc, root;
@@ -30,7 +30,7 @@ describe( 'Transaction', () => {
 	describe( 'remove', () => {
 		it( 'should remove one element', () => {
 			const position = new Position( root, [ 1 ] );
-			doc.createTransaction().remove( position );
+			doc.batch().remove( position );
 
 			expect( root.getChildCount() ).to.equal( 5 );
 			expect( root.getChild( 0 ).character ).to.equal( 'f' );
@@ -42,7 +42,7 @@ describe( 'Transaction', () => {
 
 		it( 'should remove 3 elements', () => {
 			const position = new Position( root, [ 1 ] );
-			doc.createTransaction().remove( position, 3 );
+			doc.batch().remove( position, 3 );
 
 			expect( root.getChildCount() ).to.equal( 3 );
 			expect( root.getChild( 0 ).character ).to.equal( 'f' );
@@ -52,10 +52,10 @@ describe( 'Transaction', () => {
 
 		it( 'should be chainable', () => {
 			const position = new Position( root, [ 1 ] );
-			const transaction = doc.createTransaction();
+			const batch = doc.batch();
 
-			const chain = transaction.remove( position );
-			expect( chain ).to.equal( transaction );
+			const chain = batch.remove( position );
+			expect( chain ).to.equal( batch );
 		} );
 	} );
 } );

+ 8 - 8
packages/ckeditor5-utils/tests/document/deltas/splitdelta.js

@@ -18,7 +18,7 @@ const modules = bender.amd.require(
 	'document/attribute',
 	'ckeditorerror' );
 
-describe( 'Transaction', () => {
+describe( 'Batch', () => {
 	let Document, Position, Element, Attribute, CKEditorError;
 
 	let doc, root, p;
@@ -42,7 +42,7 @@ describe( 'Transaction', () => {
 
 	describe( 'split', () => {
 		it( 'should split foobar to foo and bar', () => {
-			doc.createTransaction().split( new Position( root, [ 0, 3 ] ) );
+			doc.batch().split( new Position( root, [ 0, 3 ] ) );
 
 			expect( root.getChildCount() ).to.equal( 2 );
 
@@ -64,7 +64,7 @@ describe( 'Transaction', () => {
 		} );
 
 		it( 'should create an empty paragraph if we split at the end', () => {
-			doc.createTransaction().split( new Position( root, [ 0, 6 ] ) );
+			doc.batch().split( new Position( root, [ 0, 6 ] ) );
 
 			expect( root.getChildCount() ).to.equal( 2 );
 
@@ -87,15 +87,15 @@ describe( 'Transaction', () => {
 
 		it( 'should throw if we try to split a root', () => {
 			expect( () => {
-				doc.createTransaction().split( new Position( root, [ 0 ] ) );
-			} ).to.throw( CKEditorError, /^transaction-split-root/ );
+				doc.batch().split( new Position( root, [ 0 ] ) );
+			} ).to.throw( CKEditorError, /^batch-split-root/ );
 		} );
 
 		it( 'should be chainable', () => {
-			const transaction = doc.createTransaction();
+			const batch = doc.batch();
 
-			const chain = transaction.split( new Position( root, [ 0, 3 ] ) );
-			expect( chain ).to.equal( transaction );
+			const chain = batch.split( new Position( root, [ 0, 3 ] ) );
+			expect( chain ).to.equal( batch );
 		} );
 	} );
 } );

+ 8 - 8
packages/ckeditor5-utils/tests/document/document/document.js

@@ -10,17 +10,17 @@
 const modules = bender.amd.require(
 	'document/document',
 	'document/rootelement',
-	'document/transaction',
+	'document/batch',
 	'ckeditorerror'
 );
 
 describe( 'Document', () => {
-	let Document, RootElement, Transaction, CKEditorError;
+	let Document, RootElement, Batch, CKEditorError;
 
 	before( () => {
 		Document = modules[ 'document/document' ];
 		RootElement = modules[ 'document/rootelement' ];
-		Transaction = modules[ 'document/transaction' ];
+		Batch = modules[ 'document/batch' ];
 		CKEditorError = modules.ckeditorerror;
 	} );
 
@@ -112,12 +112,12 @@ describe( 'Document', () => {
 		} );
 	} );
 
-	describe( 'createTransaction', () => {
-		it( 'should create a new transaction with the document property', () => {
-			const transaction = document.createTransaction();
+	describe( 'batch', () => {
+		it( 'should create a new batch with the document property', () => {
+			const batch = document.batch();
 
-			expect( transaction ).to.be.instanceof( Transaction );
-			expect( transaction ).to.have.property( 'doc' ).that.equals( document );
+			expect( batch ).to.be.instanceof( Batch );
+			expect( batch ).to.have.property( 'doc' ).that.equals( document );
 		} );
 	} );
 } );

+ 0 - 82
packages/ckeditor5-utils/tests/document/transaction.js

@@ -1,82 +0,0 @@
-/**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* bender-tags: document, delta */
-
-'use strict';
-
-const modules = bender.amd.require(
-	'document/transaction',
-	'document/delta/delta',
-	'ckeditorerror' );
-
-describe( 'Transaction', () => {
-	let Transaction, Delta, CKEditorError;
-
-	before( () => {
-		Transaction = modules[ 'document/transaction' ];
-		Delta = modules[ 'document/delta/delta' ];
-		CKEditorError = modules.ckeditorerror;
-	} );
-
-	it( 'should have registered basic methods', () => {
-		const transaction = new Transaction();
-
-		expect( transaction.setAttr ).to.be.a( 'function' );
-		expect( transaction.removeAttr ).to.be.a( 'function' );
-	} );
-
-	describe( 'Transaction.register', () => {
-		let TestDelta;
-
-		before( () => {
-			TestDelta = class extends Delta {
-				constructor( transaction ) {
-					super( transaction, [] );
-				}
-			};
-		} );
-
-		afterEach( () => {
-			delete Transaction.prototype.foo;
-		} );
-
-		it( 'should register function which return an delta', () => {
-			Transaction.register( 'foo', function() {
-				this.addDelta( new TestDelta() );
-			} );
-
-			const transaction = new Transaction();
-
-			transaction.foo();
-
-			expect( transaction.deltas.length ).to.equal( 1 );
-			expect( transaction.deltas[ 0 ] ).to.be.instanceof( TestDelta );
-		} );
-
-		it( 'should register function which return an multiple deltas', () => {
-			Transaction.register( 'foo', function() {
-				this.addDelta( new TestDelta() );
-				this.addDelta( new TestDelta() );
-			} );
-
-			const transaction = new Transaction();
-
-			transaction.foo();
-
-			expect( transaction.deltas.length ).to.equal( 2 );
-			expect( transaction.deltas[ 0 ] ).to.be.instanceof( TestDelta );
-			expect( transaction.deltas[ 1 ] ).to.be.instanceof( TestDelta );
-		} );
-
-		it( 'should throw if one try to register the same transaction twice', () => {
-			Transaction.register( 'foo', () => {} );
-
-			expect( () => {
-				Transaction.register( 'foo', () => {} );
-			} ).to.throw( CKEditorError, /^transaction-register-taken/ );
-		} );
-	} );
-} );