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

Changed SchemaContext#concat to SchemaContext#push.

Oskar Wróbel 8 лет назад
Родитель
Сommit
e5aacff7d5
2 измененных файлов с 15 добавлено и 35 удалено
  1. 11 19
      packages/ckeditor5-engine/src/model/schema.js
  2. 4 16
      packages/ckeditor5-engine/tests/model/schema.js

+ 11 - 19
packages/ckeditor5-engine/src/model/schema.js

@@ -1162,39 +1162,31 @@ export class SchemaContext {
 	}
 	}
 
 
 	/**
 	/**
-	 * Returns new SchemaContext instance with additional items created from provided definition.
-	 * Definition can be:
+	 * Returns new SchemaContext instance with additional item
+	 *
+	 * Item can be added as:
 	 *
 	 *
 	 * 		const context = new SchemaContext( [ '$root' ] );
 	 * 		const context = new SchemaContext( [ '$root' ] );
 	 *
 	 *
 	 * 		// An element.
 	 * 		// An element.
 	 * 		const fooElement = writer.createElement( 'fooElement' );
 	 * 		const fooElement = writer.createElement( 'fooElement' );
-	 * 		const newContext = context.concat( fooElement ); // [ '$root', 'fooElement' ]
+	 * 		const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ]
 	 *
 	 *
 	 * 		// A text node.
 	 * 		// A text node.
 	 * 		const text = writer.createText( 'foobar' );
 	 * 		const text = writer.createText( 'foobar' );
-	 * 		const newContext = context.concat( text ); // [ '$root', '$text' ]
+	 * 		const newContext = context.push( text ); // [ '$root', '$text' ]
 	 *
 	 *
 	 * 		// A string (element name).
 	 * 		// A string (element name).
-	 * 		const newContext = context.concat( 'barElement' ); // [ '$root', 'barElement' ]
-	 *
-	 * 		// An array with above.
-	 * 		const fooElement = writer.createElement( 'fooElement' );
-	 * 		const text = writer.createText( 'foobar' );
-	 * 		const newContext = context.concat( [ fooElement, 'barElement', text ] ); // [ '$root', 'fooElement', 'barElement', '$text' ]
+	 * 		const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
 	 *
 	 *
 	 * **Note** {module:engine/model/node~Node} that is already in the model tree will be added as the only item (without ancestors).
 	 * **Note** {module:engine/model/node~Node} that is already in the model tree will be added as the only item (without ancestors).
 	 *
 	 *
-	 * @param {String|module:engine/model/node~Node|Array<String|module:engine/model/node~Node>} definition
-	 * Definition of item(s) that will be added to current context.
-	 * @returns {module:engine/model/schema~SchemaContext} New SchemaContext instance.
+	 * @param {String|module:engine/model/node~Node|Array<String|module:engine/model/node~Node>} item Item that will be added
+	 * to current context.
+	 * @returns {module:engine/model/schema~SchemaContext} New SchemaContext instance with additional item.
 	 */
 	 */
-	concat( definition ) {
-		if ( !Array.isArray( definition ) ) {
-			definition = [ definition ];
-		}
-
-		const ctx = new SchemaContext( definition );
+	push( item ) {
+		const ctx = new SchemaContext( [ item ] );
 
 
 		ctx._items = [ ...this._items, ...ctx._items ];
 		ctx._items = [ ...this._items, ...ctx._items ];
 
 

+ 4 - 16
packages/ckeditor5-engine/tests/model/schema.js

@@ -2755,11 +2755,11 @@ describe( 'SchemaContext', () => {
 		} );
 		} );
 	} );
 	} );
 
 
-	describe( 'concat()', () => {
+	describe( 'push()', () => {
 		it( 'creates new SchemaContext instance with new item - #string', () => {
 		it( 'creates new SchemaContext instance with new item - #string', () => {
 			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
 			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
 
 
-			const newCtx = ctx.concat( 'd' );
+			const newCtx = ctx.push( 'd' );
 
 
 			expect( newCtx ).to.instanceof( SchemaContext );
 			expect( newCtx ).to.instanceof( SchemaContext );
 			expect( newCtx ).to.not.equal( ctx );
 			expect( newCtx ).to.not.equal( ctx );
@@ -2771,7 +2771,7 @@ describe( 'SchemaContext', () => {
 			const node = new Text( 'd' );
 			const node = new Text( 'd' );
 			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
 			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
 
 
-			const newCtx = ctx.concat( node );
+			const newCtx = ctx.push( node );
 
 
 			expect( newCtx ).to.instanceof( SchemaContext );
 			expect( newCtx ).to.instanceof( SchemaContext );
 			expect( newCtx ).to.not.equal( ctx );
 			expect( newCtx ).to.not.equal( ctx );
@@ -2783,25 +2783,13 @@ describe( 'SchemaContext', () => {
 			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
 			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
 			const parent = new Element( 'parent', null, new Element( 'd' ) );
 			const parent = new Element( 'parent', null, new Element( 'd' ) );
 
 
-			const newCtx = ctx.concat( parent.getChild( 0 ) );
+			const newCtx = ctx.push( parent.getChild( 0 ) );
 
 
 			expect( newCtx ).to.instanceof( SchemaContext );
 			expect( newCtx ).to.instanceof( SchemaContext );
 			expect( newCtx ).to.not.equal( ctx );
 			expect( newCtx ).to.not.equal( ctx );
 			expect( Array.from( newCtx.getNames() ) ).to.deep.equal( [ 'a', 'b', 'c', 'd' ] );
 			expect( Array.from( newCtx.getNames() ) ).to.deep.equal( [ 'a', 'b', 'c', 'd' ] );
 			expect( Array.from( ctx.getNames() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
 			expect( Array.from( ctx.getNames() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
 		} );
 		} );
-
-		it( 'creates new SchemaContext instance with new item - #array', () => {
-			const ctx = new SchemaContext( [ 'a', 'b', 'c' ] );
-			const parent = new Element( 'parent', null, new Element( 'f' ) );
-
-			const newCtx = ctx.concat( [ 'd', new Text( 'e' ), parent.getChild( 0 ) ] );
-
-			expect( newCtx ).to.instanceof( SchemaContext );
-			expect( newCtx ).to.not.equal( ctx );
-			expect( Array.from( newCtx.getNames() ) ).to.deep.equal( [ 'a', 'b', 'c', 'd', '$text', 'f' ] );
-			expect( Array.from( ctx.getNames() ) ).to.deep.equal( [ 'a', 'b', 'c' ] );
-		} );
 	} );
 	} );
 
 
 	describe( 'getNames()', () => {
 	describe( 'getNames()', () => {