8
0
Pārlūkot izejas kodu

Added: engine.model.Batch#baseVersion.

Szymon Cofalik 9 gadi atpakaļ
vecāks
revīzija
c44b08ea83

+ 10 - 0
packages/ckeditor5-engine/src/model/batch.js

@@ -68,6 +68,16 @@ export default class Batch {
 		 */
 		this.type = type;
 	}
+
+	/**
+	 * Returns this batch base version, which is equal to the base version of first delta in the batch.
+	 * If there are no deltas in the batch, returns null.
+	 *
+	 * @readonly
+	 * @returns {Number|null}
+	 */
+	get baseVersion() {
+		return this.deltas.length > 0 ? this.deltas[ 0 ].baseVersion : null;
 	}
 
 	/**

+ 18 - 0
packages/ckeditor5-engine/tests/model/batch.js

@@ -100,4 +100,22 @@ describe( 'Batch', () => {
 			expect( batch.getOperations() ).to.have.property( 'next' );
 		} );
 	} );
+
+	describe( 'baseVersion', () => {
+		it( 'should return base version of first delta from the batch', () => {
+			const batch = new Batch( new Document() );
+			const delta = new Delta();
+			const operation = new Operation( 2 );
+			delta.addOperation( operation );
+			batch.addDelta( delta );
+
+			expect( batch.baseVersion ).to.equal( 2 );
+		} );
+
+		it( 'should return null if there are no deltas in batch', () => {
+			const batch = new Batch( new Document() );
+
+			expect( batch.baseVersion ).to.be.null;
+		} );
+	} );
 } );