瀏覽代碼

Refactor DowncastDispatcher#_mapChangesWithAutomaticReconversion().

Maciej Gołaszewski 5 年之前
父節點
當前提交
7c85c6465b
共有 1 個文件被更改,包括 29 次插入29 次删除
  1. 29 29
      packages/ckeditor5-engine/src/conversion/downcastdispatcher.js

+ 29 - 29
packages/ckeditor5-engine/src/conversion/downcastdispatcher.js

@@ -589,44 +589,44 @@ export default class DowncastDispatcher {
 	 * @private
 	 */
 	_mapChangesWithAutomaticReconversion( differ ) {
-		const changes = differ.getChanges();
-
 		const itemsToReconvert = new Set();
+		const updated = [];
 
-		const updated = changes
-			.map( entry => {
-				const element = getParentElementFromChange( entry );
-
-				if ( !element ) {
-					// Reconversion is done only on elements so skip text attribute changes.
-					return entry;
-				}
+		for ( const entry of differ.getChanges() ) {
+			const element = getParentElementFromChange( entry );
 
-				let eventName;
+			if ( !element ) {
+				// Reconversion is done only on elements so skip text attribute changes.
+				updated.push( entry );
 
-				if ( entry.type === 'attribute' ) {
-					eventName = `attribute:${ entry.attributeKey }:${ element.name }`;
-				} else {
-					eventName = `${ entry.type }:${ entry.name }`;
-				}
+				continue;
+			}
 
-				if ( this._isReconvertTriggerEvent( eventName, element.name ) ) {
-					if ( itemsToReconvert.has( element ) ) {
-						return null;
-					}
+			let eventName;
 
-					itemsToReconvert.add( element );
+			if ( entry.type === 'attribute' ) {
+				eventName = `attribute:${ entry.attributeKey }:${ element.name }`;
+			} else {
+				eventName = `${ entry.type }:${ entry.name }`;
+			}
 
-					return {
-						type: 'reconvert',
-						element
-					};
+			if ( this._isReconvertTriggerEvent( eventName, element.name ) ) {
+				if ( itemsToReconvert.has( element ) ) {
+					// Element is already reconverted, so skip this change.
+					continue;
 				}
 
-				return entry;
-			} )
-			// TODO: could be done in for...of loop or using reduce to not run double loop on big diffsets.
-			.filter( entry => !!entry );
+				itemsToReconvert.add( element );
+
+				// Add special "reconvert" change.
+				updated.push( {
+					type: 'reconvert',
+					element
+				} );
+			} else {
+				updated.push( entry );
+			}
+		}
 
 		return updated;
 	}