Kaynağa Gözat

Code refactoring: Changed order of class properties.

Piotrek Koszuliński 10 yıl önce
ebeveyn
işleme
bcefe4fe6d

+ 54 - 54
packages/ckeditor5-engine/src/model.js

@@ -194,6 +194,60 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], ( EmitterMixin, C
 			};
 		}
 
+		/**
+		 * Removes the binding created with {@link #bind}.
+		 *
+		 *		A.unbind( 'a' );
+		 *		A.unbind();
+		 *
+		 * @param {String...} [bindAttrs] Model attributes to unbound. All the bindings will
+		 * be released if not attributes provided.
+		 */
+		unbind( ...unbindAttrs ) {
+			if ( unbindAttrs.length ) {
+				if ( !isStringArray( unbindAttrs ) ) {
+					/**
+					 * Attributes must be strings.
+					 *
+					 * @error model-unbind-wrong-attrs
+					 */
+					throw new CKEditorError( 'model-unbind-wrong-attrs: Attributes must be strings.' );
+				}
+
+				unbindAttrs.forEach( attrName => {
+					for ( let to of this._boundTo ) {
+						// TODO, ES6 destructuring.
+						const boundModel = to[ 0 ];
+						const bindings = to[ 1 ];
+
+						for ( let boundAttrName in bindings ) {
+							if ( bindings[ boundAttrName ].has( attrName ) ) {
+								bindings[ boundAttrName ].delete( attrName );
+							}
+
+							if ( !bindings[ boundAttrName ].size ) {
+								delete bindings[ boundAttrName ];
+							}
+
+							if ( !Object.keys( bindings ).length ) {
+								this._boundTo.delete( boundModel );
+								this.stopListening( boundModel, 'change' );
+							}
+						}
+					}
+
+					delete this._bound[ attrName ];
+				} );
+			} else {
+				this._boundTo.forEach( ( bindings, boundModel ) => {
+					this.stopListening( boundModel, 'change' );
+					this._boundTo.delete( boundModel );
+				} );
+
+				this._bound = {};
+			}
+		}
+
 		/**
 		 * A chaining for {@link #bind} providing `.to()` interface.
 		 *
@@ -291,60 +345,6 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], ( EmitterMixin, C
 
 			updateModelAttrs( this, this._bindAttrs[ 0 ] );
 		}
-
-		/**
-		 * Removes the binding created with {@link #bind}.
-		 *
-		 *		A.unbind( 'a' );
-		 *		A.unbind();
-		 *
-		 * @param {String...} [bindAttrs] Model attributes to unbound. All the bindings will
-		 * be released if not attributes provided.
-		 */
-		unbind( ...unbindAttrs ) {
-			if ( unbindAttrs.length ) {
-				if ( !isStringArray( unbindAttrs ) ) {
-					/**
-					 * Attributes must be strings.
-					 *
-					 * @error model-unbind-wrong-attrs
-					 */
-					throw new CKEditorError( 'model-unbind-wrong-attrs: Attributes must be strings.' );
-				}
-
-				unbindAttrs.forEach( attrName => {
-					for ( let to of this._boundTo ) {
-						// TODO, ES6 destructuring.
-						const boundModel = to[ 0 ];
-						const bindings = to[ 1 ];
-
-						for ( let boundAttrName in bindings ) {
-							if ( bindings[ boundAttrName ].has( attrName ) ) {
-								bindings[ boundAttrName ].delete( attrName );
-							}
-
-							if ( !bindings[ boundAttrName ].size ) {
-								delete bindings[ boundAttrName ];
-							}
-
-							if ( !Object.keys( bindings ).length ) {
-								this._boundTo.delete( boundModel );
-								this.stopListening( boundModel, 'change' );
-							}
-						}
-					}
-
-					delete this._bound[ attrName ];
-				} );
-			} else {
-				this._boundTo.forEach( ( bindings, boundModel ) => {
-					this.stopListening( boundModel, 'change' );
-					this._boundTo.delete( boundModel );
-				} );
-
-				this._bound = {};
-			}
-		}
 	}
 
 	/**

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

@@ -81,34 +81,43 @@ CKEDITOR.define( [
 		}
 
 		/**
-		 * Initializes the view.
-		 */
-		init() {
-			this._initRegions();
-		}
-
-		/**
-		 * Initializes {@link #regions} of this view by passing a DOM element
-		 * generated from {@link #_regionsSelectors} into {@link Region#init}.
+		 * Element of this view. The element is rendered on first reference
+		 * using {@link #template} definition and {@link #_template} object.
 		 *
-		 * @protected
+		 * @property el
 		 */
-		_initRegions() {
-			let region, regionEl, regionSelector;
+		get el() {
+			if ( this._el ) {
+				return this._el;
+			}
 
-			for ( region of this.regions ) {
-				regionSelector = this._regionsSelectors[ region.name ];
+			if ( !this.template ) {
+				/**
+				 * Attempting to access an element of a view, which has no `template`
+				 * property.
+				 *
+				 * @error ui-view-notemplate
+				 */
+				throw new CKEditorError( 'ui-view-notemplate' );
+			}
 
-				if ( typeof regionSelector == 'string' ) {
-					regionEl = this.el.querySelector( regionSelector );
-				} else if ( typeof regionSelector == 'function' ) {
-					regionEl = regionSelector( this.el );
-				} else {
-					regionEl = null;
-				}
+			// Prepare pre–defined listeners.
+			this._prepareElementListeners( this.template );
 
-				region.init( regionEl );
-			}
+			this._template = new Template( this.template );
+
+			return ( this._el = this._template.render() );
+		}
+
+		set el( el ) {
+			this._el = el;
+		}
+
+		/**
+		 * Initializes the view.
+		 */
+		init() {
+			this._initRegions();
 		}
 
 		/**
@@ -292,39 +301,6 @@ CKEDITOR.define( [
 			this._regionsSelectors[ regionName ] = regionSelector;
 		}
 
-		/**
-		 * Element of this view. The element is rendered on first reference
-		 * using {@link #template} definition and {@link #_template} object.
-		 *
-		 * @property el
-		 */
-		get el() {
-			if ( this._el ) {
-				return this._el;
-			}
-
-			if ( !this.template ) {
-				/**
-				 * Attempting to access an element of a view, which has no `template`
-				 * property.
-				 *
-				 * @error ui-view-notemplate
-				 */
-				throw new CKEditorError( 'ui-view-notemplate' );
-			}
-
-			// Prepare pre–defined listeners.
-			this._prepareElementListeners( this.template );
-
-			this._template = new Template( this.template );
-
-			return ( this._el = this._template.render() );
-		}
-
-		set el( el ) {
-			this._el = el;
-		}
-
 		/**
 		 * 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,
@@ -395,6 +371,30 @@ CKEDITOR.define( [
 			this.model = this.regions = this.template = this._regionsSelectors = this._el = this._template = null;
 		}
 
+		/**
+		 * Initializes {@link #regions} of this view by passing a DOM element
+		 * generated from {@link #_regionsSelectors} into {@link Region#init}.
+		 *
+		 * @protected
+		 */
+		_initRegions() {
+			let region, regionEl, regionSelector;
+
+			for ( region of this.regions ) {
+				regionSelector = this._regionsSelectors[ region.name ];
+
+				if ( typeof regionSelector == 'string' ) {
+					regionEl = this.el.querySelector( regionSelector );
+				} else if ( typeof regionSelector == 'function' ) {
+					regionEl = regionSelector( this.el );
+				} else {
+					regionEl = null;
+				}
+
+				region.init( regionEl );
+			}
+		}
+
 		/**
 		 * For a given event name or callback, returns a function which,
 		 * once executed in a context of an element, attaches native DOM listener