Explorar el Código

Dropped Document#hasRoot method in favor of Document#getRoot.

Oskar Wróbel hace 8 años
padre
commit
1b4d42ebfa

+ 4 - 12
packages/ckeditor5-engine/src/model/document.js

@@ -191,7 +191,9 @@ export default class Document {
 	 * @returns {module:engine/model/rootelement~RootElement} Root registered under given name.
 	 */
 	getRoot( name = 'main' ) {
-		if ( !this.hasRoot( name ) ) {
+		const root = this.roots.get( name );
+
+		if ( !root ) {
 			/**
 			 * Root with specified name does not exist.
 			 *
@@ -204,17 +206,7 @@ export default class Document {
 			);
 		}
 
-		return this.roots.get( name );
-	}
-
-	/**
-	 * Checks if root with given name is defined.
-	 *
-	 * @param {String} name Name of root to check.
-	 * @returns {Boolean}
-	 */
-	hasRoot( name ) {
-		return !!this.roots.get( name );
+		return root;
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-engine/src/model/operation/rootattributeoperation.js

@@ -168,7 +168,7 @@ export default class RootAttributeOperation extends Operation {
 	 * @returns {module:engine/model/operation/rootattributeoperation~RootAttributeOperation}
 	 */
 	static fromJSON( json, document ) {
-		if ( !document.hasRoot( json.root ) ) {
+		if ( !document.getRoot( json.root ) ) {
 			/**
 			 * Cannot create RootAttributeOperation for document. Root with specified name does not exist.
 			 *

+ 1 - 1
packages/ckeditor5-engine/src/model/position.js

@@ -764,7 +764,7 @@ export default class Position {
 			return new Position( doc.graveyard, json.path );
 		}
 
-		if ( !doc.hasRoot( json.root ) ) {
+		if ( !doc.getRoot( json.root ) ) {
 			/**
 			 * Cannot create position for document. Root with specified name does not exist.
 			 *

+ 0 - 12
packages/ckeditor5-engine/tests/model/document/document.js

@@ -179,18 +179,6 @@ describe( 'Document', () => {
 		} );
 	} );
 
-	describe( 'hasRoot()', () => {
-		it( 'should return true when Document has RootElement with given name', () => {
-			doc.createRoot();
-
-			expect( doc.hasRoot( 'main' ) ).to.be.true;
-		} );
-
-		it( 'should return false when Document does not have RootElement with given name', () => {
-			expect( doc.hasRoot( 'noroot' ) ).to.be.false;
-		} );
-	} );
-
 	describe( 'selection', () => {
 		it( 'should get updated attributes whenever attribute operation is applied', () => {
 			sinon.spy( doc.selection, '_updateAttributes' );