ソースを参照

Aligned View to the new Template API.

Aleksander Nowodzinski 9 年 前
コミット
e1a86e9beb
2 ファイル変更12 行追加21 行削除
  1. 3 12
      packages/ckeditor5-ui/src/view.js
  2. 9 9
      packages/ckeditor5-ui/tests/view.js

+ 3 - 12
packages/ckeditor5-ui/src/view.js

@@ -61,7 +61,7 @@ export default class View {
 		/**
 		 * Template of this view.
 		 *
-		 * @member {Object} ui.View#template
+		 * @member {ui.Template} ui.View#template
 		 */
 
 		/**
@@ -78,13 +78,6 @@ export default class View {
 		 * @private
 		 * @member {HTMLElement} ui.View.#_element
 		 */
-
-		/**
-		 * An instance of Template to generate {@link ui.View#_el}.
-		 *
-		 * @private
-		 * @member {ui.Template} ui.View#_template
-		 */
 	}
 
 	/**
@@ -103,9 +96,7 @@ export default class View {
 			return null;
 		}
 
-		this._template = new Template( this.template );
-
-		return ( this._element = this._template.render() );
+		return ( this._element = this.template.render() );
 	}
 
 	set element( el ) {
@@ -254,7 +245,7 @@ export default class View {
 		}
 
 		this.model = this.regions = this.template = this.locale = this.t = null;
-		this._regionSelectors = this._element = this._template = null;
+		this._regionSelectors = this._element = null;
 	}
 
 	/**

+ 9 - 9
packages/ckeditor5-ui/tests/view.js

@@ -57,13 +57,13 @@ describe( 'View', () => {
 
 	describe( 'init', () => {
 		beforeEach( () => {
-			setTestViewClass( () => ( {
+			setTestViewClass( {
 				tag: 'p',
 				children: [
 					{ tag: 'span' },
 					{ tag: 'strong' }
 				]
-			} ) );
+			} );
 		} );
 
 		it( 'calls child regions #init', () => {
@@ -178,12 +178,12 @@ describe( 'View', () => {
 		} );
 
 		it( 'should override an existing region with override flag', () => {
-			view.template = {
+			view.template = new Template( {
 				tag: 'div',
 				children: [
 					{ tag: 'span' }
 				]
-			};
+			} );
 
 			const region1 = new Region( 'x' );
 			const region2 = new Region( 'x' );
@@ -381,20 +381,20 @@ describe( 'View', () => {
 } );
 
 function createViewInstanceWithTemplate() {
-	setTestViewClass( () => ( { tag: 'a' } ) );
+	setTestViewClass( { tag: 'a' } );
 	setTestViewInstance();
 }
 
-function setTestViewClass( templateFn, regionsFn ) {
+function setTestViewClass( templateDef, regionsFn ) {
 	TestView = class V extends View {
 		constructor( model ) {
 			super( model );
 
-			if ( templateFn ) {
-				this.template = templateFn.call( this );
+			if ( templateDef ) {
+				this.template = new Template( templateDef );
 			}
 
-			if ( templateFn && regionsFn ) {
+			if ( templateDef && regionsFn ) {
 				regionsFn.call( this );
 			}
 		}