瀏覽代碼

Changed the order of params to avoid issues like the one added in tests. Now the order conforms to the one in editor.setData().

Piotrek Koszuliński 9 年之前
父節點
當前提交
3c8bb7ab81
共有 2 個文件被更改,包括 19 次插入10 次删除
  1. 3 8
      packages/ckeditor5-engine/src/datacontroller.js
  2. 16 2
      packages/ckeditor5-engine/tests/datacontroller.js

+ 3 - 8
packages/ckeditor5-engine/src/datacontroller.js

@@ -158,15 +158,10 @@ export default class DataController {
 	 * This method also creates a batch with all the changes applied. If all you need is to parse data use
 	 * the {@link engine.dataController#parse} method.
 	 *
-	 * @param {String} [rootName='main'] Roots name.
 	 * @param {String} data Input data.
+	 * @param {String} [rootName='main'] Root name.
 	 */
-	set( rootName, data ) {
-		if ( !data ) {
-			data = rootName;
-			rootName = 'main';
-		}
-
+	set( data, rootName = 'main' ) {
 		// Save to model.
 		const modelRoot = this.model.getRoot( rootName );
 
@@ -197,7 +192,7 @@ export default class DataController {
 	}
 
 	/**
-	 * Removes all events listeners set by the DataController.
+	 * Removes all event listeners set by the DataController.
 	 */
 	destroy() {}
 }

+ 16 - 2
packages/ckeditor5-engine/tests/datacontroller.js

@@ -93,14 +93,28 @@ describe( 'DataController', () => {
 
 		it( 'should get root name as a parameter', () => {
 			schema.allow( { name: '$text', inside: '$root' } );
-			data.set( 'main', 'foo' );
-			data.set( 'title', 'Bar' );
+			data.set( 'foo', 'main' );
+			data.set( 'Bar', 'title' );
 
 			expect( getData( modelDocument, { withoutSelection: true, rootName: 'main' } ) ).to.equal( 'foo' );
 			expect( getData( modelDocument, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );
 
 			expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 );
 		} );
+
+		// This case was added when order of params was different and it really didn't work. Let's keep it
+		// if anyone will ever try to change this.
+		it( 'should allow setting empty data', () => {
+			schema.allow( { name: '$text', inside: '$root' } );
+
+			data.set( 'foo', 'title' );
+
+			expect( getData( modelDocument, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'foo' );
+
+			data.set( '', 'title' );
+
+			expect( getData( modelDocument, { withoutSelection: true, rootName: 'title' } ) ).to.equal( '' );
+		} );
 	} );
 
 	describe( 'get', () => {