8
0
Просмотр исходного кода

Added iterator interface to the Config class.

Piotr Jasiun 6 лет назад
Родитель
Сommit
cd30910c68
2 измененных файлов с 17 добавлено и 0 удалено
  1. 11 0
      packages/ckeditor5-utils/src/config.js
  2. 6 0
      packages/ckeditor5-utils/tests/config.js

+ 11 - 0
packages/ckeditor5-utils/src/config.js

@@ -113,6 +113,17 @@ export default class Config {
 		return this._getFromSource( this._config, name );
 	}
 
+	/**
+	 * Iterable interface.
+	 *
+	 * Iterates over all top level configuration names.
+	 *
+	 * @returns {Iterable.<String>}
+	 */
+	[ Symbol.iterator ]() {
+		return Object.keys( this._config )[ Symbol.iterator ]();
+	}
+
 	/**
 	 * Saves passed configuration to the specified target (nested object).
 	 *

+ 6 - 0
packages/ckeditor5-utils/tests/config.js

@@ -459,4 +459,10 @@ describe( 'Config', () => {
 			expect( nodesAgain ).to.deep.equal( nodes );
 		} );
 	} );
+
+	describe( 'iterator', () => {
+		it( 'should return top level keys of the configuration', () => {
+			expect( Array.from( config ) ).to.be.deep.equal( [ 'creator', 'language', 'resize', 'toolbar', 'options' ] );
+		} );
+	} );
 } );