8
0
Эх сурвалжийг харах

Removed treeModel.Attribute#register.

Szymon Cofalik 10 жил өмнө
parent
commit
9f19d9bd02

+ 0 - 43
packages/ckeditor5-engine/src/treemodel/attribute.js

@@ -46,11 +46,6 @@ export default class Attribute {
 		 */
 		this._hash = this.key + ': ' + JSON.stringify( this.value, sort );
 
-		// If attribute is already registered the registered one should be returned.
-		if ( Attribute._register[ this._hash ] ) {
-			return Attribute._register[ this._hash ];
-		}
-
 		// We do not care about the order, so collections with the same elements should return the same hash.
 		function sort( key, value ) {
 			if ( !langUtils.isArray( value ) && langUtils.isObject( value ) ) {
@@ -82,42 +77,4 @@ export default class Attribute {
 	isEqual( otherAttr ) {
 		return this._hash === otherAttr._hash;
 	}
-
-	/**
-	 * To save memory, commonly used attributes may be registered. If an attribute is registered the constructor will
-	 * always return the same instance of this attribute.
-	 *
-	 * Note that attributes are registered globally.
-	 *
-	 *		let attr1 = Attribute.register( 'bold', true );
-	 *		let attr2 = Attribute.register( 'bold', true );
-	 *		let attr3 = new Attribute( 'bold', true );
-	 *		attr1 === attr2 // true
-	 *		attr1 === attr3 // true
-	 *
-	 * @static
-	 * @param {String} key Attribute key.
-	 * @param {Mixed} value Attribute value.
-	 * @returns {treeModel.Attribute} Registered attribute.
-	 */
-	static register( key, value ) {
-		const attr = new Attribute( key, value );
-
-		if ( this._register[ attr._hash ] ) {
-			return this._register[ attr._hash ];
-		} else {
-			this._register[ attr._hash ] = attr;
-
-			return attr;
-		}
-	}
 }
-
-/**
- * Register of attributes in which all registered attributes are stored.
- *
- * @static
- * @private
- * @property {String} _hash
- */
-Attribute._register = {};

+ 0 - 47
packages/ckeditor5-engine/tests/treemodel/attribute.js

@@ -10,10 +10,6 @@
 import Attribute from '/ckeditor5/core/treemodel/attribute.js';
 
 describe( 'Attribute', () => {
-	beforeEach( () => {
-		Attribute._register = {};
-	} );
-
 	describe( 'constructor', () => {
 		it( 'should create attribute', () => {
 			let attr = new Attribute( 'foo', 'bar' );
@@ -28,48 +24,5 @@ describe( 'Attribute', () => {
 
 			expect( attr1.isEqual( attr2 ) ).to.be.true;
 		} );
-
-		it( 'should return the same object for registered objects', () => {
-			Attribute.register( 'register', true );
-
-			let attr1 = new Attribute( 'register', true );
-			let attr2 = new Attribute( 'register', true );
-
-			expect( attr1 ).to.equal( attr2 );
-			expect( attr1.isEqual( attr2 ) ).to.be.true;
-		} );
-
-		it( 'should return different objects for different values', () => {
-			Attribute.register( 'register', true );
-
-			let attr1 = new Attribute( 'register', true );
-			let attr2 = new Attribute( 'register', false );
-
-			expect( attr1 ).to.not.be.equals( attr2 );
-			expect( attr1.isEqual( attr2 ) ).to.not.be.true;
-		} );
-
-		it( 'should return different objects for not registered objects', () => {
-			Attribute.register( 'register', true );
-
-			let attr1 = new Attribute( 'register', false );
-			let attr2 = new Attribute( 'register', false );
-
-			expect( attr1 ).to.not.be.equals( attr2 );
-			expect( attr1.isEqual( attr2 ) ).to.be.true;
-		} );
-	} );
-
-	describe( 'register', () => {
-		it( 'Attribute.register should return registered attribute', () => {
-			let attr1 = new Attribute( 'register', true );
-			let attr2 = Attribute.register( 'register', true );
-			let attr3 = Attribute.register( 'register', true );
-			let attr4 = new Attribute( 'register', true );
-
-			expect( attr1 ).to.not.be.equals( attr2 );
-			expect( attr2 ).to.equal( attr3 );
-			expect( attr3 ).to.equal( attr4 );
-		} );
 	} );
 } );