Parcourir la source

Allow creating virtual views (without elements). Fixed symbol names.

Piotrek Koszuliński il y a 10 ans
Parent
commit
7becb52b4c

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

@@ -13,8 +13,8 @@ import DOMEmitterMixin from './domemittermixin.js';
 import utils from '../utils.js';
 import isPlainObject from '../lib/lodash/isPlainObject.js';
 
-const bindToSymbol = Symbol( 'bind-to' );
-const bindIfSymbol = Symbol( 'bind-if' );
+const bindToSymbol = Symbol( 'bindTo' );
+const bindIfSymbol = Symbol( 'bindIf' );
 
 /**
  * Basic View class.
@@ -86,14 +86,9 @@ export default class View {
 			return this._element;
 		}
 
+		// No template means no element (a virtual view).
 		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' );
+			return null;
 		}
 
 		// Prepare pre–defined listeners.

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

@@ -42,10 +42,7 @@ describe( 'View', () => {
 			expect( view._regionsSelectors ).to.be.empty;
 			expect( view._element ).to.be.null;
 			expect( view._template ).to.be.null;
-
-			expect( () => {
-				view.element;
-			} ).to.throw( CKEditorError, /ui-view-notemplate/ );
+			expect( view.element ).to.be.null;
 		} );
 	} );