Przeglądaj źródła

Use separate position classes.

Maciej Gołaszewski 5 lat temu
rodzic
commit
60130a325a

+ 52 - 15
packages/ckeditor5-engine/tests/manual/performance/position.js

@@ -54,13 +54,13 @@ function runTest( name, callback ) {
 	} );
 }
 
-class Position {
-	constructor( root, path, stickiness = 'left', pathMergeMethod ) {
+class PositionConcat {
+	constructor( root, path, stickiness = 'left' ) {
 		if ( !( path instanceof Array ) || path.length === 0 ) {
 			throw new Error( 'model-position-path-incorrect-format' );
 		}
 
-		path = pathMergeMethod( root.path, path );
+		path = root.path.concat( path );
 		root = root.root;
 
 		this.root = root;
@@ -69,28 +69,65 @@ class Position {
 	}
 }
 
-function testConcat( root, path ) {
-	return new Position( root, path, 'right', concat );
+class PositionSpread {
+	constructor( root, path, stickiness = 'left' ) {
+		if ( !( path instanceof Array ) || path.length === 0 ) {
+			throw new Error( 'model-position-path-incorrect-format' );
+		}
+
+		path = [ ...root.path, ...path ];
+		root = root.root;
+
+		this.root = root;
+		this.path = path;
+		this.stickiness = stickiness;
+	}
 }
 
-function testSpread( root, path ) {
-	return new Position( root, path, 'right', spread );
+class PositionForLoop {
+	constructor( root, path, stickiness = 'left' ) {
+		if ( !( path instanceof Array ) || path.length === 0 ) {
+			throw new Error( 'model-position-path-incorrect-format' );
+		}
+
+		path = forLoop( root.path, path );
+		root = root.root;
+
+		this.root = root;
+		this.path = path;
+		this.stickiness = stickiness;
+	}
 }
 
-function testForLoop( root, path ) {
-	return new Position( root, path, 'right', forLoop );
+class PositionUltraForLoop {
+	constructor( root, path, stickiness = 'left' ) {
+		if ( !( path instanceof Array ) || path.length === 0 ) {
+			throw new Error( 'model-position-path-incorrect-format' );
+		}
+
+		path = ultraForLoop( root.path, path );
+		root = root.root;
+
+		this.root = root;
+		this.path = path;
+		this.stickiness = stickiness;
+	}
 }
 
-function testUltraForLoop( root, path ) {
-	return new Position( root, path, 'right', ultraForLoop );
+function testConcat( root, path ) {
+	return new PositionConcat( root, path );
 }
 
-function concat( rootPath, path ) {
-	return rootPath.concat( path );
+function testSpread( root, path ) {
+	return new PositionSpread( root, path );
 }
 
-function spread( rootPath, path ) {
-	return [ ...rootPath, ...path ];
+function testForLoop( root, path ) {
+	return new PositionForLoop( root, path );
+}
+
+function testUltraForLoop( root, path ) {
+	return new PositionUltraForLoop( root, path );
 }
 
 function forLoop( rootPath, path ) {