소스 검색

Renamed View#bind->View#bindToAttribute.

Aleksander Nowodzinski 10 년 전
부모
커밋
7a8994a977
2개의 변경된 파일20개의 추가작업 그리고 19개의 파일을 삭제
  1. 9 9
      packages/ckeditor5-engine/src/ui/view.js
  2. 11 10
      packages/ckeditor5-engine/tests/ui/view.js

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

@@ -136,23 +136,23 @@ CKEDITOR.define( [
 		}
 
 		/**
-		 * Binds a `property` of View's model so the DOM of the View is updated when the `property`
+		 * Binds an `attribute` of View's model so the DOM of the View is updated when the `attribute`
 		 * changes. It returns a function which, once called in the context of a DOM element,
 		 * attaches a listener to the model which, in turn, brings changes to DOM.
 		 *
-		 * @param {String} property Property name in the model to be observed.
-		 * @param {Function} [callback] Callback function executed on property change in model.
+		 * @param {String} attribute Attribute name in the model to be observed.
+		 * @param {Function} [callback] Callback function executed on attribute change in model.
 		 * If not specified, a default DOM `domUpdater` supplied by the template is used.
 		 */
-		bind( property, callback ) {
+		bindToAttribute( attribute, callback ) {
 			/**
-			 * Attaches a listener to View's model, which updates DOM when the model's property
+			 * Attaches a listener to View's model, which updates DOM when the model's attribute
 			 * changes. DOM is either updated by the `domUpdater` function supplied by the template
 			 * (like attribute changer or `innerHTML` setter) or custom `callback` passed to {@link #bind}.
 			 *
 			 * This function is called by {@link Template#render}.
 			 *
-			 * @param {HTMLElement} el DOM element to be updated when `property` in model changes.
+			 * @param {HTMLElement} el DOM element to be updated when `attribute` in model changes.
 			 * @param {Function} domUpdater A function provided by the template which updates corresponding
 			 * DOM.
 			 */
@@ -160,11 +160,11 @@ CKEDITOR.define( [
 				// TODO: Use ES6 default arguments syntax.
 				callback = callback || domUpdater;
 
-				// Execute callback when the property changes.
-				this.listenTo( this.model, 'change:' + property, onModelChange );
+				// Execute callback when the attribute changes.
+				this.listenTo( this.model, 'change:' + attribute, onModelChange );
 
 				// Set the initial state of the view.
-				onModelChange( null, this.model[ property ] );
+				onModelChange( null, this.model[ attribute ] );
 
 				function onModelChange( evt, value ) {
 					let processedValue = callback( el, value );

+ 11 - 10
packages/ckeditor5-engine/tests/ui/view.js

@@ -9,7 +9,7 @@
 'use strict';
 
 const modules = bender.amd.require( 'ckeditor', 'ui/view', 'ui/region', 'ckeditorerror', 'model', 'eventinfo' );
-let View, TestView;
+let View, TestView, Model;
 let view;
 
 bender.tools.createSinonSandbox();
@@ -50,14 +50,14 @@ describe( 'instance', () => {
 	} );
 } );
 
-describe( 'bind', () => {
+describe( 'bindToAttribute', () => {
 	beforeEach( createViewInstanceWithTemplate );
 
 	it( 'returns a function that passes arguments', () => {
 		setTestViewInstance( { a: 'foo' } );
 
 		let spy = bender.sinon.spy();
-		let callback = view.bind( 'a', spy );
+		let callback = view.bindToAttribute( 'a', spy );
 
 		expect( spy.called ).to.be.false;
 
@@ -75,7 +75,7 @@ describe( 'bind', () => {
 			return {
 				tag: 'p',
 				attrs: {
-					'class': this.bind( 'foo' )
+					'class': this.bindToAttribute( 'foo' )
 				},
 				text: 'abc'
 			};
@@ -99,7 +99,7 @@ describe( 'bind', () => {
 						text: 'baz'
 					}
 				],
-				text: this.bind( 'foo' )
+				text: this.bindToAttribute( 'foo' )
 			};
 		} );
 
@@ -120,9 +120,9 @@ describe( 'bind', () => {
 			return {
 				tag: 'p',
 				attrs: {
-					'class': this.bind( 'foo', callback )
+					'class': this.bindToAttribute( 'foo', callback )
 				},
-				text: this.bind( 'foo', callback )
+				text: this.bindToAttribute( 'foo', callback )
 			};
 		} );
 
@@ -138,7 +138,7 @@ describe( 'bind', () => {
 			return {
 				tag: 'p',
 				attrs: {
-					'class': this.bind( 'foo', ( el, value ) => {
+					'class': this.bindToAttribute( 'foo', ( el, value ) => {
 						el.innerHTML = value;
 
 						if ( value == 'changed' ) {
@@ -434,7 +434,7 @@ describe( 'destroy', () => {
 		setTestViewClass( function() {
 			return {
 				tag: 'p',
-				text: this.bind( 'foo' )
+				text: this.bindToAttribute( 'foo' )
 			};
 		} );
 
@@ -457,6 +457,7 @@ describe( 'destroy', () => {
 
 function updateModuleReference() {
 	View = modules[ 'ui/view' ];
+	Model = modules.model;
 }
 
 function createViewInstanceWithTemplate() {
@@ -477,7 +478,7 @@ function setTestViewClass( template ) {
 }
 
 function setTestViewInstance( model ) {
-	view = new TestView( model );
+	view = new TestView( new Model( model ) );
 
 	if ( view.template ) {
 		document.body.appendChild( view.el );