浏览代码

Made core.treeModel.Document#_roots a private property. Changed order in the class.

Szymon Cofalik 9 年之前
父节点
当前提交
903019800c

+ 22 - 20
packages/ckeditor5-engine/src/treemodel/document.js

@@ -40,14 +40,6 @@ export default class Document {
 	 * Creates an empty document instance with no {@link core.treeModel.Document#roots} (other than graveyard).
 	 */
 	constructor() {
-		/**
-		 * List of roots that are owned and managed by this document.
-		 *
-		 * @readonly
-		 * @member {Map} core.treeModel.Document#roots
-		 */
-		this.roots = new Map();
-
 		/**
 		 * Document version. It starts from `0` and every operation increases the version number. It is used to ensure that
 		 * operations are applied on the proper document version. If the {@link core.treeModel.operation.Operation#baseVersion} will
@@ -58,14 +50,6 @@ export default class Document {
 		 */
 		this.version = 0;
 
-		/**
-		 * Array of pending changes. See: {@link core.treeModel.Document#enqueueChanges}.
-		 *
-		 * @private
-		 * @member {Array.<Function>} core.treeModel.Document#_pendingChanges
-		 */
-		this._pendingChanges = [];
-
 		/**
 		 * Selection done on this document.
 		 *
@@ -81,6 +65,24 @@ export default class Document {
 		 */
 		this.schema = new Schema();
 
+		/**
+		 * Array of pending changes. See: {@link core.treeModel.Document#enqueueChanges}.
+		 *
+		 * @private
+		 * @member {Array.<Function>} core.treeModel.Document#_pendingChanges
+		 */
+		this._pendingChanges = [];
+
+		/**
+		 * List of roots that are owned and managed by this document. Use {@link core.treeModel.document#createRoot} and
+		 * {@link core.treeModel.document#getRoot} to manipulate it.
+		 *
+		 * @readonly
+		 * @protected
+		 * @member {Map} core.treeModel.Document#roots
+		 */
+		this._roots = new Map();
+
 		// Add events that will update selection attributes.
 		this.selection.on( 'update', () => {
 			this.selection._updateAttributes();
@@ -151,7 +153,7 @@ export default class Document {
 	 * @returns {core.treeModel.RootElement} Created root.
 	 */
 	createRoot( id, name ) {
-		if ( this.roots.has( id ) ) {
+		if ( this._roots.has( id ) ) {
 			/**
 			 * Root with specified id already exists.
 			 *
@@ -166,7 +168,7 @@ export default class Document {
 		}
 
 		const root = new RootElement( this, name || id );
-		this.roots.set( id, root );
+		this._roots.set( id, root );
 
 		return root;
 	}
@@ -210,7 +212,7 @@ export default class Document {
 	 * @returns {core.treeModel.RootElement} Root registered under given id.
 	 */
 	getRoot( id ) {
-		if ( !this.roots.has( id ) ) {
+		if ( !this._roots.has( id ) ) {
 			/**
 			 * Root with specified id does not exist.
 			 *
@@ -223,7 +225,7 @@ export default class Document {
 			);
 		}
 
-		return this.roots.get( id );
+		return this._roots.get( id );
 	}
 
 	/**

+ 3 - 3
packages/ckeditor5-engine/tests/treemodel/document/document.js

@@ -21,8 +21,8 @@ describe( 'Document', () => {
 
 	describe( 'constructor', () => {
 		it( 'should create Document with no data, empty graveyard and empty selection', () => {
-			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.getChildCount() ).to.equal( 0 );
 			expect( doc.selection.getRanges().length ).to.equal( 0 );
@@ -33,7 +33,7 @@ describe( 'Document', () => {
 		it( 'should create a new RootElement, add it to roots map and return it', () => {
 			let root = doc.createRoot( 'root', 'root' );
 
-			expect( doc.roots.size ).to.equal( 2 );
+			expect( doc._roots.size ).to.equal( 2 );
 			expect( root ).to.be.instanceof( RootElement );
 			expect( root.getChildCount() ).to.equal( 0 );
 		} );