Browse Source

Batch should be created only through change block.

Piotr Jasiun 8 years ago
parent
commit
717804bc2b

+ 7 - 11
packages/ckeditor5-engine/src/model/model.js

@@ -49,15 +49,15 @@ export default class Model {
 		}
 		}
 	}
 	}
 
 
-	enqueueChange( batch, callback ) {
-		if ( typeof batch === 'string' ) {
-			batch = this.batch( batch );
-		} else if ( typeof batch == 'function' ) {
-			callback = batch;
-			batch = this.batch();
+	enqueueChange( batchOrType, callback ) {
+		if ( typeof batchOrType === 'string' ) {
+			batchOrType = new Batch( batchOrType );
+		} else if ( typeof batchOrType == 'function' ) {
+			callback = batchOrType;
+			batchOrType = new Batch();
 		}
 		}
 
 
-		this._pendingChanges.push( { batch, callback } );
+		this._pendingChanges.push( { batchOrType, callback } );
 
 
 		if ( this._pendingChanges.length == 1 ) {
 		if ( this._pendingChanges.length == 1 ) {
 			this._runPendingChanges();
 			this._runPendingChanges();
@@ -86,10 +86,6 @@ export default class Model {
 		return ret;
 		return ret;
 	}
 	}
 
 
-	batch( type ) {
-		return new Batch( type );
-	}
-
 	applyOperation( operation ) {
 	applyOperation( operation ) {
 		return operation._execute();
 		return operation._execute();
 	}
 	}

+ 7 - 8
packages/ckeditor5-engine/tests/model/model.js

@@ -4,7 +4,6 @@
  */
  */
 
 
 import Model from '../../src/model/model';
 import Model from '../../src/model/model';
-import Batch from '../../src/model/batch';
 
 
 describe( 'Model', () => {
 describe( 'Model', () => {
 	let model;
 	let model;
@@ -61,7 +60,7 @@ describe( 'Model', () => {
 		} );
 		} );
 
 
 		it( 'should execute enqueueChanges immediately if its the first block', () => {
 		it( 'should execute enqueueChanges immediately if its the first block', () => {
-			model.enqueueChange( new Batch(), () => {
+			model.enqueueChange( () => {
 				changes += 'A';
 				changes += 'A';
 
 
 				nested();
 				nested();
@@ -81,7 +80,7 @@ describe( 'Model', () => {
 		} );
 		} );
 
 
 		it( 'should be possible to enqueueChanges immediately if its the first block', () => {
 		it( 'should be possible to enqueueChanges immediately if its the first block', () => {
-			model.enqueueChange( new Batch(), () => {
+			model.enqueueChange( () => {
 				changes += 'A';
 				changes += 'A';
 
 
 				nested();
 				nested();
@@ -90,14 +89,14 @@ describe( 'Model', () => {
 			expect( changes ).to.equal( 'AB' );
 			expect( changes ).to.equal( 'AB' );
 
 
 			function nested() {
 			function nested() {
-				const ret = model.change( () => {
+				model.change( () => {
 					changes += 'B';
 					changes += 'B';
 				} );
 				} );
 			}
 			}
 		} );
 		} );
 
 
 		it( 'should be possible to nest change in enqueueChanges', () => {
 		it( 'should be possible to nest change in enqueueChanges', () => {
-			model.enqueueChange( new Batch(), () => {
+			model.enqueueChange( () => {
 				changes += 'A';
 				changes += 'A';
 
 
 				nested();
 				nested();
@@ -119,7 +118,7 @@ describe( 'Model', () => {
 		} );
 		} );
 
 
 		it( 'should be possible to nest enqueueChanges in enqueueChanges', () => {
 		it( 'should be possible to nest enqueueChanges in enqueueChanges', () => {
-			model.enqueueChange( new Batch(), () => {
+			model.enqueueChange( () => {
 				changes += 'A';
 				changes += 'A';
 
 
 				nestedEnqueue();
 				nestedEnqueue();
@@ -130,7 +129,7 @@ describe( 'Model', () => {
 			expect( changes ).to.equal( 'ABC' );
 			expect( changes ).to.equal( 'ABC' );
 
 
 			function nestedEnqueue() {
 			function nestedEnqueue() {
-				model.enqueueChange( new Batch(), () => {
+				model.enqueueChange( () => {
 					changes += 'C';
 					changes += 'C';
 				} );
 				} );
 			}
 			}
@@ -152,7 +151,7 @@ describe( 'Model', () => {
 			expect( changes ).to.equal( 'ABCD' );
 			expect( changes ).to.equal( 'ABCD' );
 
 
 			function nestedEnqueue() {
 			function nestedEnqueue() {
-				model.enqueueChange( new Batch(), () => {
+				model.enqueueChange( () => {
 					changes += 'C';
 					changes += 'C';
 				} );
 				} );
 			}
 			}