8
0
Эх сурвалжийг харах

Code refactoring: Throw once.

Piotrek Koszuliński 9 жил өмнө
parent
commit
9f5dd508b0

+ 12 - 8
packages/ckeditor5-engine/src/view/emptyelement.js

@@ -23,12 +23,7 @@ export default class EmptyElement extends Element {
 		super( name, attributes );
 
 		if ( arguments.length > 2 ) {
-			/**
-			 * Cannot add children to {@link engine.view.EmptyElement}.
-			 *
-			 * @error view-emptyelement-cannot-add
-			 */
-			throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
+			throwCannotAdd();
 		}
 	}
 
@@ -55,7 +50,7 @@ export default class EmptyElement extends Element {
 	 * to EmptyElement.
 	 */
 	appendChildren() {
-		throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
+		throwCannotAdd();
 	}
 
 	/**
@@ -64,7 +59,7 @@ export default class EmptyElement extends Element {
 	 * to EmptyElement.
 	 */
 	insertChildren() {
-		throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
+		throwCannotAdd();
 	}
 
 	/**
@@ -76,3 +71,12 @@ export default class EmptyElement extends Element {
 		return null;
 	}
 }
+
+function throwCannotAdd() {
+	/**
+	 * Cannot add children to {@link engine.view.EmptyElement}.
+	 *
+	 * @error view-emptyelement-cannot-add
+	 */
+	throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
+}