浏览代码

Changed text get/set methods to a setter and getter.

Piotrek Koszuliński 10 年之前
父节点
当前提交
6c3d5a8ecf

+ 2 - 2
packages/ckeditor5-engine/src/treeview/converter.js

@@ -77,7 +77,7 @@ export default class Converter {
 		}
 		// Texts.
 		else if ( domNode instanceof Text && viewNode instanceof ViewText ) {
-			return domNode.data === viewNode.getText();
+			return domNode.data === viewNode.data;
 		}
 
 		// Not matching types.
@@ -101,7 +101,7 @@ export default class Converter {
 		}
 
 		if ( viewNode instanceof ViewText ) {
-			return domDocument.createTextNode( viewNode.getText() );
+			return domDocument.createTextNode( viewNode.data );
 		} else {
 			if ( this.getCorrespondingDom( viewNode ) ) {
 				return this.getCorrespondingDom( viewNode );

+ 1 - 1
packages/ckeditor5-engine/src/treeview/observer/mutationobserver.js

@@ -126,7 +126,7 @@ export default class MutationObserver extends Observer {
 					// we will have only one in the map.
 					mutatedTexts.set( text, {
 						type: 'text',
-						oldText: text.getText(),
+						oldText: text.data,
 						newText: mutation.target.data,
 						node: text
 					} );

+ 2 - 2
packages/ckeditor5-engine/src/treeview/renderer.js

@@ -139,8 +139,8 @@ export default class Renderer {
 		function updateText( viewText ) {
 			const domText = converter.getCorrespondingDom( viewText );
 
-			if ( domText.data != viewText.getText() ) {
-				domText.data = viewText.getText();
+			if ( domText.data != viewText.data ) {
+				domText.data = viewText.data;
 			}
 		}
 

+ 14 - 17
packages/ckeditor5-engine/src/treeview/text.js

@@ -14,40 +14,37 @@ import Node from './node.js';
  */
 export default class Text extends Node {
 	/**
-	 * Creates a tree view text.
+	 * Creates a tree view text node.
 	 *
-	 * @param {String} text Text.
+	 * @param {String} data Text.
 	 * @constructor
 	 */
-	constructor( text ) {
+	constructor( data ) {
 		super();
 
 		/**
-		 * Text data.
+		 * The text content.
 		 *
-		 * @property {String}
 		 * @private
+		 * @property {String}
 		 */
-		this._text = text;
+		this._data = data;
 	}
 
 	/**
-	 * Gets text data.
+	 * The text content.
+	 *
+	 * Setting the data fires the {@link treeView.Node#change change event}.
 	 *
-	 * @returns {String} Text data.
+	 * @property {String} Text data.
 	 */
-	getText() {
-		return this._text;
+	get data() {
+		return this._data;
 	}
 
-	/**
-	 * Sets text data and fire {@link treeView.Node#change change event}.
-	 *
-	 * @param {String} text Text data.
-	 */
-	setText( text ) {
+	set data( data ) {
 		this._fireChange( 'TEXT', this );
 
-		this._text = text;
+		this._data = data;
 	}
 }

+ 2 - 2
packages/ckeditor5-engine/tests/treeview/converter.js

@@ -83,7 +83,7 @@ describe( 'converter', () => {
 
 			expect( viewP.getChildCount() ).to.equal( 2 );
 			expect( viewP.getChild( 0 ).name ).to.equal( 'img' );
-			expect( viewP.getChild( 1 ).getText() ).to.equal( 'foo' );
+			expect( viewP.getChild( 1 ).data ).to.equal( 'foo' );
 
 			expect( converter.getCorrespondingDom( viewP ) ).to.not.equal( domP );
 			expect( converter.getCorrespondingDom( viewP.getChild( 0 ) ) ).to.equal( domImg );
@@ -109,7 +109,7 @@ describe( 'converter', () => {
 
 			expect( viewP.getChildCount() ).to.equal( 2 );
 			expect( viewP.getChild( 0 ).name ).to.equal( 'img' );
-			expect( viewP.getChild( 1 ).getText() ).to.equal( 'foo' );
+			expect( viewP.getChild( 1 ).data ).to.equal( 'foo' );
 
 			expect( converter.getCorrespondingDom( viewP ) ).to.equal( domP );
 			expect( converter.getCorrespondingDom( viewP.getChild( 0 ) ) ).to.equal( domP.childNodes[ 0 ] );

+ 1 - 1
packages/ckeditor5-engine/tests/treeview/node.js

@@ -205,7 +205,7 @@ describe( 'Node', () => {
 
 		describe( 'removeChildren', () => {
 			it( 'should fire change event', () => {
-				text.setText( 'bar' );
+				text.data = 'bar';
 
 				sinon.assert.calledOnce( rootChangeSpy );
 				sinon.assert.calledWith( rootChangeSpy, 'TEXT', text );

+ 2 - 2
packages/ckeditor5-engine/tests/treeview/observer/mutationobserver.js

@@ -63,11 +63,11 @@ describe( 'MutationObserver', () => {
 		expect( lastMutations[ 0 ].node ).to.equal( treeView.viewRoot.getChild( 0 ) );
 
 		expect( lastMutations[ 0 ].newChildren.length ).to.equal( 2 );
-		expect( lastMutations[ 0 ].newChildren[ 0 ].getText() ).to.equal( 'f' );
+		expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'f' );
 		expect( lastMutations[ 0 ].newChildren[ 1 ].name ).to.equal( 'b' );
 
 		expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 1 );
-		expect( lastMutations[ 0 ].oldChildren[ 0 ].getText() ).to.equal( 'foo' );
+		expect( lastMutations[ 0 ].oldChildren[ 0 ].data ).to.equal( 'foo' );
 	} );
 
 	it( 'should deduplicate text changes', () => {

+ 3 - 3
packages/ckeditor5-engine/tests/treeview/renderer.js

@@ -66,7 +66,7 @@ describe( 'Renderer', () => {
 		it( 'should mark text which need update', () => {
 			const viewText = new ViewText( 'foo' );
 			viewNode.appendChildren( viewText );
-			viewText.setText( 'bar' );
+			viewText.data = 'bar';
 
 			renderer.markToSync( 'TEXT', viewText );
 
@@ -79,7 +79,7 @@ describe( 'Renderer', () => {
 			viewNode = new ViewElement( 'p' );
 
 			viewNode.appendChildren( viewText );
-			viewText.setText( 'bar' );
+			viewText.data = 'bar';
 
 			renderer.markToSync( 'TEXT', viewText );
 
@@ -173,7 +173,7 @@ describe( 'Renderer', () => {
 			expect( domNode.childNodes.length ).to.equal( 1 );
 			expect( domNode.childNodes[ 0 ].data ).to.equal( 'foo' );
 
-			viewText.setText( 'bar' );
+			viewText.data = 'bar';
 
 			renderer.markToSync( 'TEXT', viewText );
 			renderer.render();

+ 3 - 3
packages/ckeditor5-engine/tests/treeview/text.js

@@ -16,7 +16,7 @@ describe( 'Element', () => {
 			const text = new ViewText( 'foo' );
 
 			expect( text ).to.be.an.instanceof( ViewNode );
-			expect( text.getText() ).to.equal( 'foo' );
+			expect( text.data ).to.equal( 'foo' );
 			expect( text ).to.have.property( 'parent' ).that.is.null;
 		} );
 	} );
@@ -24,9 +24,9 @@ describe( 'Element', () => {
 	describe( 'setText', () => {
 		it( 'should change the text', () => {
 			const text = new ViewText( 'foo' );
-			text.setText( 'bar' );
+			text.data = 'bar';
 
-			expect( text.getText() ).to.equal( 'bar' );
+			expect( text.data ).to.equal( 'bar' );
 		} );
 	} );
 } );