8
0
Просмотр исходного кода

Changed Editor#context property from readonly to protected.

Oskar Wróbel 6 лет назад
Родитель
Сommit
70627e5f2c

+ 9 - 9
packages/ckeditor5-core/src/editor/editor.js

@@ -55,11 +55,11 @@ export default class Editor {
 		 * The editor context.
 		 * When it is not provided through the configuration then the editor creates it.
 		 *
-		 * @readonly
+		 * @protected
 		 * @type {module:core/context~Context}
 		 */
-		this.context = config.context || new Context( { language: config.language } );
-		this.context.addEditor( this, !config.context );
+		this._context = config.context || new Context( { language: config.language } );
+		this._context.addEditor( this, !config.context );
 
 		const availablePlugins = this.constructor.builtinPlugins;
 
@@ -74,7 +74,7 @@ export default class Editor {
 		 */
 		this.config = new Config( config, this.constructor.defaultConfig );
 		this.config.define( 'plugins', availablePlugins );
-		this.config.define( this.context.getConfigForEditor() );
+		this.config.define( this._context.getConfigForEditor() );
 
 		/**
 		 * The plugins loaded and in use by this editor instance.
@@ -84,13 +84,13 @@ export default class Editor {
 		 * @readonly
 		 * @member {module:core/plugincollection~PluginCollection}
 		 */
-		this.plugins = new PluginCollection( this, availablePlugins, this.context.plugins );
+		this.plugins = new PluginCollection( this, availablePlugins, this._context.plugins );
 
 		/**
 		 * @readonly
 		 * @type {module:utils/locale~Locale}
 		 */
-		this.locale = this.context.locale;
+		this.locale = this._context.locale;
 
 		/**
 		 * Shorthand for {@link module:utils/locale~Locale#t}.
@@ -254,12 +254,12 @@ export default class Editor {
 			.then( () => {
 				// Remove the editor from the context to avoid destroying it
 				// one more time when context will be destroyed.
-				this.context.removeEditor( this );
+				this._context.removeEditor( this );
 
 				// When the editor was an owner of the context then
 				// the context should be destroyed along with the editor.
-				if ( this.context.isCreatedByEditor ) {
-					return this.context.destroy();
+				if ( this._context.isCreatedByEditor ) {
+					return this._context.destroy();
 				}
 			} ).then( () => {
 				this.fire( 'destroy' );

+ 9 - 9
packages/ckeditor5-core/tests/editor/editor.js

@@ -185,16 +185,16 @@ describe( 'Editor', () => {
 		it( 'should create a new context when it is not provided through config', () => {
 			const editor = new TestEditor();
 
-			expect( editor.context ).to.be.an.instanceof( Context );
-			expect( editor.context.isCreatedByEditor ).to.true;
+			expect( editor._context ).to.be.an.instanceof( Context );
+			expect( editor._context.isCreatedByEditor ).to.true;
 		} );
 
 		it( 'should use context given through configuration when is defined', async () => {
 			const context = await Context.create();
 			const editor = new TestEditor( { context } );
 
-			expect( editor.context ).to.equal( context );
-			expect( editor.context.isCreatedByEditor ).to.false;
+			expect( editor._context ).to.equal( context );
+			expect( editor._context.isCreatedByEditor ).to.false;
 		} );
 
 		it( 'should throw when try to use context created by one editor with the other editor', () => {
@@ -202,13 +202,13 @@ describe( 'Editor', () => {
 
 			expectToThrowCKEditorError( () => {
 				// eslint-disable-next-line no-new
-				new TestEditor( { context: editor.context } );
+				new TestEditor( { context: editor._context } );
 			}, /^context-addEditor-to-private-context/ );
 		} );
 
 		it( 'should destroy context created by the editor on editor destroy', async () => {
 			const editor = await TestEditor.create();
-			const contextDestroySpy = sinon.spy( editor.context, 'destroy' );
+			const contextDestroySpy = sinon.spy( editor._context, 'destroy' );
 
 			await editor.destroy();
 
@@ -218,7 +218,7 @@ describe( 'Editor', () => {
 		it( 'should not destroy context along with the editor when context was injected to the editor', async () => {
 			const context = await Context.create();
 			const editor = await TestEditor.create( { context } );
-			const contextDestroySpy = sinon.spy( editor.context, 'destroy' );
+			const contextDestroySpy = sinon.spy( editor._context, 'destroy' );
 
 			await editor.destroy();
 
@@ -286,8 +286,8 @@ describe( 'Editor', () => {
 		it( 'should use Context#locale and Context#t', () => {
 			const editor = new TestEditor();
 
-			expect( editor.locale ).to.equal( editor.context.locale ).to.instanceof( Locale );
-			expect( editor.t ).to.equal( editor.context.t );
+			expect( editor.locale ).to.equal( editor._context.locale ).to.instanceof( Locale );
+			expect( editor.t ).to.equal( editor._context.t );
 		} );
 
 		it( 'should use locale instance with a proper configuration', () => {