Преглед на файлове

Created View#setTemplate and View#extendTemplate methods.

Aleksander Nowodzinski преди 8 години
родител
ревизия
05a272af4b

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

@@ -37,7 +37,7 @@ import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable';
  *				// Views define their interface (state) using observable attributes.
  *				this.set( 'elementClass', 'bar' );
  *
- *				this.template = new Template( {
+ *				this.setTemplate( {
  *					tag: 'p',
  *
  *					// The element of the view can be defined with its children.
@@ -99,7 +99,7 @@ export default class View {
 		 *				super();
 		 *
 		 *				// A template instance the #element will be created from.
-		 *				this.template = new Template( {
+		 *				this.setTemplate( {
 		 *					tag: 'p'
 		 *
 		 *					// ...
@@ -211,7 +211,7 @@ export default class View {
 	 *				 	isEnabled: true
 	 *				 } );
 	 *
-	 *				this.template = new Template( {
+	 *				this.setTemplate( {
 	 *					tag: 'p',
 	 *
 	 *					attributes: {
@@ -251,7 +251,7 @@ export default class View {
 	 *
 	 *				this.items = this.createCollection();
  	 *
-	 *				this.template = new Template( {
+	 *				this.setTemplate( {
 	 *					tag: 'p',
 	 *
 	 *					// `items` collection will render here.
@@ -296,7 +296,7 @@ export default class View {
 	 *				this.childA = new SomeChildView( locale );
 	 *				this.childB = new SomeChildView( locale );
 	 *
-	 *				this.template = new Template( { tag: 'p' } );
+	 *				this.setTemplate( { tag: 'p' } );
 	 *
 	 *				// Register the children.
 	 *				this.registerChildren( [ this.childA, this.childB ] );
@@ -327,7 +327,7 @@ export default class View {
 	 *				this.childA = new SomeChildView( locale );
 	 *				this.childB = new SomeChildView( locale );
 	 *
-	 *				this.template = new Template( {
+	 *				this.setTemplate( {
 	 *					tag: 'p',
 	 *
  	 *					// These children will be added automatically. There's no
@@ -374,7 +374,7 @@ export default class View {
 	 *
 	 * A shorthand for:
 	 *
-	 *		view.template = new Template( definition );
+	 *		view.setTemplate( definition );
 	 *
 	 * @param {@link module:ui/template~TemplateDefinition} definition Definition of view's template.
 	 */
@@ -421,7 +421,7 @@ export default class View {
 	 *
 	 *		class SampleView extends View {
 	 *			constructor() {
-	 *				this.template = new Template( {
+	 *				this.setTemplate( {
 	 *					// ...
 	 *				} );
 	 *			},
@@ -445,7 +445,7 @@ export default class View {
 	 *		const view = new SampleView();
 	 *
 	 *		// Let's customize the view before it gets rendered.
-	 *		Template.extend( view.template, {
+	 *		view.extendTemplate( {
 	 *			attributes: {
 	 *				class: [
 	 *					'additional-class'

+ 2 - 2
packages/ckeditor5-ui/tests/template.js

@@ -546,7 +546,7 @@ describe( 'Template', () => {
 				// words to explain it. But what actually matters is that it proves the Template
 				// class is free of "Maximum call stack size exceeded" error in certain
 				// situations.
-				view.template = new Template( {
+				view.setTemplate( {
 					tag: 'span',
 
 					children: [
@@ -2972,7 +2972,7 @@ function dispatchEvent( el, domEvtName ) {
 function getView( def ) {
 	const view = new View();
 
-	view.template = new Template( def );
+	view.setTemplate( def );
 
 	return view;
 }

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

@@ -204,7 +204,7 @@ describe( 'View', () => {
 		it( 'should set view#isRendered', () => {
 			const view = new View();
 
-			view.template = new Template( {
+			view.setTemplate( {
 				tag: 'div'
 			} );
 
@@ -266,11 +266,11 @@ describe( 'View', () => {
 			const viewB = new View();
 			const viewC = new View();
 
-			viewA.template = new Template( { tag: 'a' } );
-			viewB.template = new Template( { tag: 'b' } );
-			viewC.template = new Template( { tag: 'c' } );
+			viewA.setTemplate( { tag: 'a' } );
+			viewB.setTemplate( { tag: 'b' } );
+			viewC.setTemplate( { tag: 'c' } );
 
-			view.template = new Template( {
+			view.setTemplate( {
 				tag: 'div',
 				children: [
 					viewA,
@@ -384,7 +384,7 @@ function setTestViewClass( templateDef ) {
 			this.locale = { t() {} };
 
 			if ( templateDef ) {
-				this.template = new Template( templateDef );
+				this.setTemplate( templateDef );
 			}
 		}
 	};
@@ -405,7 +405,7 @@ function createViewWithChildren() {
 		constructor() {
 			super();
 
-			this.template = new Template( {
+			this.setTemplate( {
 				tag: 'span'
 			} );
 		}

+ 2 - 3
packages/ckeditor5-ui/tests/viewcollection.js

@@ -9,7 +9,6 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import View from '../src/view';
 import ViewCollection from '../src/viewcollection';
-import Template from '../src/template';
 import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
 
 let collection;
@@ -76,7 +75,7 @@ describe( 'ViewCollection', () => {
 				function getView( text ) {
 					const view = new View();
 
-					view.template = new Template( {
+					view.setTemplate( {
 						tag: 'li',
 						children: [
 							{
@@ -93,7 +92,7 @@ describe( 'ViewCollection', () => {
 				collection.add( viewB );
 
 				// Put the collection in the template.
-				view.template = new Template( {
+				view.setTemplate( {
 					tag: 'ul',
 					children: collection
 				} );