8
0
Quellcode durchsuchen

Changed: Use `getAttributeKeys()` instead of `getAttributes()`.

Szymon Cofalik vor 9 Jahren
Ursprung
Commit
7f91c451a9

+ 11 - 11
packages/ckeditor5-engine/src/conversion/modelconversiondispatcher.js

@@ -179,12 +179,12 @@ export default class ModelConversionDispatcher {
 			// Fire a separate addAttribute event for each attribute that was set on inserted items.
 			// This is important because most attributes converters will listen only to add/change/removeAttribute events.
 			// If we would not add this part, attributes on inserted nodes would not be converted.
-			for ( let attr of item.getAttributes() ) {
-				data.attributeKey = attr[ 0 ];
+			for ( let key of item.getAttributeKeys() ) {
+				data.attributeKey = key;
 				data.attributeOldValue = null;
-				data.attributeNewValue = attr[ 1 ];
+				data.attributeNewValue = item.getAttribute( key );
 
-				this._testAndFire( 'addAttribute:' + attr[ 0 ], data, consumable );
+				this._testAndFire( 'addAttribute:' + key, data, consumable );
 			}
 		}
 	}
@@ -268,9 +268,9 @@ export default class ModelConversionDispatcher {
 
 		this.fire( 'selection', data, consumable, this.conversionApi );
 
-		for ( let attr of selection.getAttributes() ) {
-			data.key = attr[ 0 ];
-			data.value = attr[ 1 ];
+		for ( let key of selection.getAttributeKeys() ) {
+			data.key = key;
+			data.value = selection.getAttribute( key );
 
 			// Do not fire event if the attribute has been consumed.
 			if ( consumable.test( selection, 'selectionAttribute:' + data.key ) ) {
@@ -295,8 +295,8 @@ export default class ModelConversionDispatcher {
 
 			consumable.add( item, 'insert' );
 
-			for ( let attr of item.getAttributes() ) {
-				consumable.add( item, 'addAttribute:' + attr[ 0 ] );
+			for ( let key of item.getAttributeKeys() ) {
+				consumable.add( item, 'addAttribute:' + key );
 			}
 		}
 
@@ -337,8 +337,8 @@ export default class ModelConversionDispatcher {
 
 		consumable.add( selection, 'selection' );
 
-		for ( let attr of selection.getAttributes() ) {
-			consumable.add( selection, 'selectionAttribute:' + attr[ 0 ] );
+		for ( let key of selection.getAttributeKeys() ) {
+			consumable.add( selection, 'selectionAttribute:' + key );
 		}
 
 		return consumable;

+ 3 - 4
packages/ckeditor5-engine/src/conversion/view-converter-builder.js

@@ -257,8 +257,7 @@ class ViewConverterBuilder {
 					const modelElement = element instanceof Function ? element( data.input ) : new ModelElement( element );
 
 					// Check whether generated structure is okay with `Schema`.
-					// TODO: Make it more sane after .getAttributeKeys() is available for ModelElement.
-					const keys = Array.from( modelElement.getAttributes() ).map( ( attribute ) => attribute[ 0 ] );
+					const keys = Array.from( modelElement.getAttributeKeys() );
 
 					if ( !conversionApi.schema.check( { name: modelElement.name, attributes: keys, inside: data.context } ) ) {
 						continue;
@@ -384,8 +383,8 @@ function setAttributeOn( toChange, attribute, data, conversionApi ) {
 		return;
 	}
 
-	// TODO: Make it more sane after .getAttributeKeys() is available for ModelElement.
-	const keys = Array.from( toChange.getAttributes() ).map( ( attribute ) => attribute[ 0 ] ).concat( attribute.key );
+	const keys = Array.from( toChange.getAttributeKeys() );
+	keys.push( attribute.key );
 
 	const schemaQuery = {
 		name: toChange.name || '$text',