瀏覽代碼

Changed: made model.Document#_roots public and renamed to #roots.

Szymon Cofalik 8 年之前
父節點
當前提交
6765a39e95

+ 8 - 9
packages/ckeditor5-engine/src/model/document.js

@@ -104,10 +104,9 @@ export default class Document {
 		 * {@link #getRoot} to manipulate it.
 		 *
 		 * @readonly
-		 * @protected
 		 * @member {Map}
 		 */
-		this._roots = new Map();
+		this.roots = new Map();
 
 		// Add events that will ensure selection correctness.
 		this.selection.on( 'change:range', () => {
@@ -192,7 +191,7 @@ export default class Document {
 	 * @returns {module:engine/model/rootelement~RootElement} Created root.
 	 */
 	createRoot( elementName = '$root', rootName = 'main' ) {
-		if ( this._roots.has( rootName ) ) {
+		if ( this.roots.has( rootName ) ) {
 			/**
 			 * Root with specified name already exists.
 			 *
@@ -207,7 +206,7 @@ export default class Document {
 		}
 
 		const root = new RootElement( this, elementName, rootName );
-		this._roots.set( rootName, root );
+		this.roots.set( rootName, root );
 
 		return root;
 	}
@@ -251,7 +250,7 @@ export default class Document {
 	 * @returns {module:engine/model/rootelement~RootElement} Root registered under given name.
 	 */
 	getRoot( name = 'main' ) {
-		if ( !this._roots.has( name ) ) {
+		if ( !this.roots.has( name ) ) {
 			/**
 			 * Root with specified name does not exist.
 			 *
@@ -264,7 +263,7 @@ export default class Document {
 			);
 		}
 
-		return this._roots.get( name );
+		return this.roots.get( name );
 	}
 
 	/**
@@ -274,7 +273,7 @@ export default class Document {
 	 * @returns {Boolean}
 	 */
 	hasRoot( name ) {
-		return this._roots.has( name );
+		return this.roots.has( name );
 	}
 
 	/**
@@ -283,7 +282,7 @@ export default class Document {
 	 * @returns {Array.<String>} Roots names.
 	 */
 	getRootNames() {
-		return Array.from( this._roots.keys() ).filter( ( name ) => name != graveyardName );
+		return Array.from( this.roots.keys() ).filter( ( name ) => name != graveyardName );
 	}
 
 	/**
@@ -360,7 +359,7 @@ export default class Document {
 	 * @returns {module:engine/model/rootelement~RootElement} The default root for this document.
 	 */
 	_getDefaultRoot() {
-		for ( let root of this._roots.values() ) {
+		for ( let root of this.roots.values() ) {
 			if ( root !== this.graveyard ) {
 				return root;
 			}

+ 4 - 4
packages/ckeditor5-engine/tests/model/document/document.js

@@ -23,8 +23,8 @@ describe( 'Document', () => {
 
 	describe( 'constructor()', () => {
 		it( 'should create Document with no data, empty graveyard and selection set to default range', () => {
-			expect( doc ).to.have.property( '_roots' ).that.is.instanceof( Map );
-			expect( doc._roots.size ).to.equal( 1 );
+			expect( doc ).to.have.property( 'roots' ).that.is.instanceof( Map );
+			expect( doc.roots.size ).to.equal( 1 );
 			expect( doc.graveyard ).to.be.instanceof( RootElement );
 			expect( doc.graveyard.maxOffset ).to.equal( 0 );
 			expect( count( doc.selection.getRanges() ) ).to.equal( 1 );
@@ -50,7 +50,7 @@ describe( 'Document', () => {
 		it( 'should create a new RootElement with default element and root names, add it to roots map and return it', () => {
 			let root = doc.createRoot();
 
-			expect( doc._roots.size ).to.equal( 2 );
+			expect( doc.roots.size ).to.equal( 2 );
 			expect( root ).to.be.instanceof( RootElement );
 			expect( root.maxOffset ).to.equal( 0 );
 			expect( root ).to.have.property( 'name', '$root' );
@@ -60,7 +60,7 @@ describe( 'Document', () => {
 		it( 'should create a new RootElement with custom element and root names, add it to roots map and return it', () => {
 			let root = doc.createRoot( 'customElementName', 'customRootName' );
 
-			expect( doc._roots.size ).to.equal( 2 );
+			expect( doc.roots.size ).to.equal( 2 );
 			expect( root ).to.be.instanceof( RootElement );
 			expect( root.maxOffset ).to.equal( 0 );
 			expect( root ).to.have.property( 'name', 'customElementName' );