8
0
Quellcode durchsuchen

A prototype of Controller class API.

Aleksander Nowodzinski vor 10 Jahren
Ursprung
Commit
942a783091

+ 65 - 0
packages/ckeditor5-engine/src/ui/controller.js

@@ -0,0 +1,65 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+CKEDITOR.define( [ 'collection', 'model' ], function( Collection, Model ) {
+	class Controller extends Model {
+		/**
+		 * @constructor
+		 */
+		constructor( model, view ) {
+			super();
+
+			this.model = model;
+			this.view = view;
+
+			this.controllers = new Collection();
+		}
+
+		/**
+		 * @param
+		 * @returns
+		 */
+		init() {
+			// Note: Because this.view.init() can by sync as well as async,
+			// this method is not returning this.view.init() directly.
+			return Promise.resolve()
+				.then( () => {
+					return this.view.init();
+				} );
+		}
+
+		/**
+		 * @param
+		 * @returns
+		 */
+		append( controller, regionName ) {
+			this.controllers.add( controller );
+
+			// Note: Because controller.init() can by sync as well as async,
+			// it is wrapped in promise.
+			return Promise.resolve()
+				.then( () => {
+					return controller.init();
+				} )
+				.then( () => {
+					this.view.append( controller.view, regionName );
+				} )
+				.then( () => {
+					return controller;
+				} );
+		}
+
+		/**
+		 * @param
+		 * @returns
+		 */
+		destroy() {
+		}
+	}
+
+	return Controller;
+} );

+ 4 - 0
packages/ckeditor5-engine/src/ui/region.js

@@ -57,6 +57,10 @@ CKEDITOR.define( [ 'collection', 'model' ], ( Collection, Model ) => {
 				this.views.remove( view ).destroy();
 			}
 		}
+
+		append( view ) {
+			this.views.add( view );
+		}
 	}
 
 	return Region;

+ 12 - 0
packages/ckeditor5-engine/src/ui/view.js

@@ -54,6 +54,14 @@ CKEDITOR.define( [
 			 */
 		}
 
+		/**
+		 * @param
+		 * @returns
+		 */
+		init() {
+			// TODO: What if we used render() here?
+		}
+
 		/**
 		 * Element of this view. The element is rendered on first reference.
 		 *
@@ -259,6 +267,10 @@ CKEDITOR.define( [
 				def.children.map( this._prepareElementListeners, this );
 			}
 		}
+
+		append( view, regionName ) {
+			this.regions.get( regionName ).append( view );
+		}
 	}
 
 	utils.extend( View.prototype, DOMEmitterMixin );