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

Removed model from View class.

Oskar Wrobel 9 лет назад
Родитель
Сommit
c1c93b378a

+ 11 - 18
packages/ckeditor5-ui/src/view.js

@@ -3,12 +3,12 @@
  * For licensing, see LICENSE.md.
  */
 
-import Model from './model.js';
 import Collection from '../utils/collection.js';
 import Region from './region.js';
 import Template from './template.js';
 import CKEditorError from '../utils/ckeditorerror.js';
 import DOMEmitterMixin from './domemittermixin.js';
+import ObservableMixin from '../utils/observablemixin.js';
 import mix from '../utils/mix.js';
 
 /**
@@ -24,13 +24,6 @@ export default class View {
 	 * @param {utils.Locale} [locale] The {@link core.editor.Editor#locale editor's locale} instance.
 	 */
 	constructor( locale ) {
-		/**
-		 * Model of this view.
-		 *
-		 * @member {ui.Model} ui.View#model
-		 */
-		this.model = new Model();
-
 		/**
 		 * @readonly
 		 * @member {utils.Locale} ui.View#locale
@@ -79,10 +72,10 @@ export default class View {
 
 		/**
 		 * Cached {@link ui.Template} binder object specific for this instance.
-		 * See {@link ui.View#bind}.
+		 * See {@link ui.View#templateBind}.
 		 *
 		 * @private
-		 * @member {Object} ui.View.#_bind
+		 * @member {Object} ui.View.#_templateBind
 		 */
 	}
 
@@ -113,19 +106,18 @@ export default class View {
 	}
 
 	/**
-	 * Shorthand for {@link ui.Template#bind}, bound to {@link ui.View#model}
-	 * and {@link ui.View} on the first access.
+	 * Shorthand for {@link ui.Template#bind}, bound to {@link ui.View} on the first access.
 	 *
-	 * Cached {@link ui.Template#bind} object is stored in {@link ui.View.#_bind}.
+	 * Cached {@link ui.Template#bind} object is stored in {@link ui.View.#_templateBind}.
 	 *
-	 * @method ui.View#bind
+	 * @method ui.View#templateBind
 	 */
-	get bind() {
-		if ( this._bind ) {
-			return this._bind;
+	get templateBind() {
+		if ( this._templateBind ) {
+			return this._templateBind;
 		}
 
-		return ( this._bind = Template.bind( this.model, this ) );
+		return ( this._templateBind = Template.bind( this, this ) );
 	}
 
 	/**
@@ -267,6 +259,7 @@ export default class View {
 }
 
 mix( View, DOMEmitterMixin );
+mix( View, ObservableMixin );
 
 const validSelectorTypes = new Set( [ 'string', 'boolean', 'function' ] );
 

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

@@ -512,7 +512,7 @@ function defineItemControllerClass() {
 		constructor( model, view ) {
 			super( model, view );
 
-			view.model.bind( 'uid' ).to( model );
+			view.bind( 'uid' ).to( model );
 		}
 	};
 }
@@ -522,7 +522,7 @@ function defineItemViewClass() {
 		constructor( locale ) {
 			super( locale );
 
-			const bind = this.bind;
+			const bind = this.templateBind;
 
 			this.template = new Template( {
 				tag: 'li',

+ 4 - 6
packages/ckeditor5-ui/tests/view.js

@@ -122,12 +122,12 @@ describe( 'View', () => {
 		} );
 
 		it( 'returns a shorthand for Template binding', () => {
-			expect( view.bind.to ).to.be.a( 'function' );
-			expect( view.bind.if ).to.be.a( 'function' );
+			expect( view.templateBind.to ).to.be.a( 'function' );
+			expect( view.templateBind.if ).to.be.a( 'function' );
 
-			const binding = view.bind.to( 'a' );
+			const binding = view.templateBind.to( 'a' );
 
-			expect( binding.observable ).to.equal( view.model );
+			expect( binding.observable ).to.equal( view );
 			expect( binding.emitter ).to.equal( view );
 		} );
 	} );
@@ -217,8 +217,6 @@ describe( 'View', () => {
 		it( 'invokes out of #template', () => {
 			setTestViewInstance();
 
-			view.model.set( 'a', 1 );
-
 			expect( view.element ).to.be.an.instanceof( HTMLElement );
 			expect( view.element.nodeName ).to.equal( 'A' );
 		} );