Procházet zdrojové kódy

Code style: Don't use Symbols for protected properties in model's Position and Range.

Maciej Gołaszewski před 8 roky
rodič
revize
0667f06c10

+ 3 - 3
packages/ckeditor5-engine/src/model/liveposition.js

@@ -7,7 +7,7 @@
  * @module engine/model/liveposition
  */
 
-import Position, { setPath, setRoot } from './position';
+import Position from './position';
 import Range from './range';
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
@@ -194,8 +194,8 @@ function transform( type, range, position ) {
 	if ( !this.isEqual( transformed ) ) {
 		const oldPosition = Position.createFromPosition( this );
 
-		setPath( this, transformed.path );
-		setRoot( this, transformed.root );
+		this._path = transformed.path;
+		this._root = transformed.root;
 
 		this.fire( 'change', oldPosition );
 	}

+ 3 - 3
packages/ckeditor5-engine/src/model/liverange.js

@@ -7,7 +7,7 @@
  * @module engine/model/liverange
  */
 
-import Range, { setStart, setEnd } from './range';
+import Range from './range';
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 
@@ -178,8 +178,8 @@ function transform( changeType, deltaType, batch, targetRange, sourcePosition )
 		// If range boundaries have changed, fire `change:range` event.
 		const oldRange = Range.createFromRange( this );
 
-		setStart( this, updated.start );
-		setEnd( this, updated.end );
+		this._start = updated.start;
+		this._end = updated.end;
 
 		this.fire( 'change:range', oldRange, {
 			type: changeType,

+ 18 - 27
packages/ckeditor5-engine/src/model/position.js

@@ -13,9 +13,6 @@ import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Text from './text';
 
-const _path = Symbol( 'path' );
-const _root = Symbol( 'root' );
-
 /**
  * Represents a position in the model tree.
  *
@@ -73,8 +70,22 @@ export default class Position {
 		// Make path immutable
 		Object.freeze( path );
 
-		setRoot( this, root.root );
-		setPath( this, path );
+		/**
+		 * Root of the position path.
+		 *
+		 * @protected
+		 * @member {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment}
+		 * module:engine/model/position~Position#_root
+		 */
+		this._root = root.root;
+
+		/**
+		 * Position of the node in the tree.
+		 *
+		 * @protected
+		 * @member {Array.<Number>} module:engine/model/position~Position#_path
+		 */
+		this._path = path;
 	}
 
 	/**
@@ -107,7 +118,7 @@ export default class Position {
 	 * @member {Array.<Number>} module:engine/model/position~Position#path
 	 */
 	get path() {
-		return this[ _path ];
+		return this._path;
 	}
 
 	/**
@@ -118,7 +129,7 @@ export default class Position {
 	 * module:engine/model/position~Position#root
 	 */
 	get root() {
-		return this[ _root ];
+		return this._root;
 	}
 
 	/**
@@ -817,26 +828,6 @@ export default class Position {
 	}
 }
 
-/**
- * Method used to expose root setter to child classes.
- * @protected
- * @param {module:engine/model/position~Position} position Position of which root should be modified.
- * @param {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment} root Root of the position.
- */
-export function setRoot( position, root ) {
-	position[ _root ] = root;
-}
-
-/**
- * Method used to expose path setter to child classes.
- * @protected
- * @param {module:engine/model/position~Position} position Position of which path should be modified.
- * @param {Array.<Number>} path Position path. See {@link module:engine/model/position~Position#path}.
- */
-export function setPath( position, path ) {
-	position[ _path ] = path;
-}
-
 // Helper for setting offset on give path array.
 // @private
 // @param {Array.<Number>} path Position path. See {@link module:engine/model/position~Position#path}.

+ 17 - 28
packages/ckeditor5-engine/src/model/range.js

@@ -11,9 +11,6 @@ import Position from './position';
 import TreeWalker from './treewalker';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
-const _start = Symbol( 'start' );
-const _end = Symbol( 'end' );
-
 /**
  * Range class. Range is iterable.
  */
@@ -27,8 +24,21 @@ export default class Range {
 	 * @param {module:engine/model/position~Position} [end] End position. If not set, range will be collapsed at `start` position.
 	 */
 	constructor( start, end = null ) {
-		setStart( this, start );
-		setEnd( this, end ? end : start );
+		/**
+		 * Start position.
+		 *
+		 * @protected
+		 * @member {module:engine/model/position~Position}
+		 */
+		this._start = start;
+
+		/**
+		 * End position.
+		 *
+		 * @protected
+		 * @member {module:engine/model/position~Position}
+		 */
+		this._end = end ? end : start;
 	}
 
 	/**
@@ -54,7 +64,7 @@ export default class Range {
 	 * @member {module:engine/model/position~Position}
 	 */
 	get start() {
-		return this[ _start ];
+		return this._start;
 	}
 
 	/**
@@ -64,7 +74,7 @@ export default class Range {
 	 * @member {module:engine/model/position~Position}
 	 */
 	get end() {
-		return this[ _end ];
+		return this._end;
 	}
 
 	/**
@@ -867,24 +877,3 @@ export default class Range {
 		return new this( Position.fromJSON( json.start, doc ), Position.fromJSON( json.end, doc ) );
 	}
 }
-
-/**
- * Method used to expose start setter to child classes.
- * @protected
- * @param {module:engine/model/range~Range} range Range of which start position should be sent.
- * @param {module:engine/model/position~Position} position Position to set as range start.
- * See {@link module:engine/model/range~Range#start}.
- */
-export function setStart( range, position ) {
-	range[ _start ] = position;
-}
-
-/**
- * Method used to expose end setter to child classes.
- * @protected
- * @param {module:engine/model/range~Range} range Range of which end position should be sent.
- * @param {module:engine/model/position~Position} position Position to set as range end. See {@link module:engine/model/range~Range#end}.
- */
-export function setEnd( range, position ) {
-	range[ _end ] = position;
-}