Sfoglia il codice sorgente

Internal: Reuse existing function to create a Map.

Also fixed API docs, as the function is supposed to work with Iterables, see the attrs parameter type in view/Element's constructor (https://ckeditor.com/docs/ckeditor5/15.0.0/api/module_engine_view_element-Element.html#function-constructor).
Marek Lewandowski 6 anni fa
parent
commit
2192ab9d9a
1 ha cambiato i file con 4 aggiunte e 8 eliminazioni
  1. 4 8
      packages/ckeditor5-engine/src/view/element.js

+ 4 - 8
packages/ckeditor5-engine/src/view/element.js

@@ -10,7 +10,7 @@
 import Node from './node';
 import Text from './text';
 import TextProxy from './textproxy';
-import objectToMap from '@ckeditor/ckeditor5-utils/src/objecttomap';
+import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
 import isIterable from '@ckeditor/ckeditor5-utils/src/isiterable';
 import Matcher from './matcher';
 import { isPlainObject } from 'lodash-es';
@@ -853,17 +853,13 @@ export default class Element extends Node {
 }
 
 // Parses attributes provided to the element constructor before they are applied to an element. If attributes are passed
-// as an object (instead of `Map`), the object is transformed to the map. Attributes with `null` value are removed.
+// as an object (instead of `Iterable`), the object is transformed to the map. Attributes with `null` value are removed.
 // Attributes with non-`String` value are converted to `String`.
 //
-// @param {Object|Map} attrs Attributes to parse.
+// @param {Object|Iterable} attrs Attributes to parse.
 // @returns {Map} Parsed attributes.
 function parseAttributes( attrs ) {
-	if ( attrs instanceof Map ) {
-		attrs = new Map( attrs );
-	} else {
-		attrs = objectToMap( attrs );
-	}
+	attrs = toMap( attrs );
 
 	for ( const [ key, value ] of attrs ) {
 		if ( value === null ) {