From f9bd16eafae4d341dcd20dd251a8dba00833d7de Mon Sep 17 00:00:00 2001 From: Piotr Jasiun Date: Thu, 21 Nov 2019 15:07:09 +0100 Subject: [PATCH 1/2] Added iterator interface to the Config class. --- src/config.js | 11 +++++++++++ tests/config.js | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/config.js b/src/config.js index ecad1b0..fb13b1c 100644 --- a/src/config.js +++ b/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.} + */ + [ Symbol.iterator ]() { + return Object.keys( this._config )[ Symbol.iterator ](); + } + /** * Saves passed configuration to the specified target (nested object). * diff --git a/tests/config.js b/tests/config.js index 5b3f0c9..76ef846 100644 --- a/tests/config.js +++ b/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' ] ); + } ); + } ); } ); From d3e2d350e5cc782e6fa8dc8c46c16d44e545c077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Thu, 5 Dec 2019 14:58:29 +0100 Subject: [PATCH 2/2] Changes Config iterator interface to Config#names() method. --- src/config.js | 8 ++++---- tests/config.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/config.js b/src/config.js index fb13b1c..ce7657d 100644 --- a/src/config.js +++ b/src/config.js @@ -114,14 +114,14 @@ export default class Config { } /** - * Iterable interface. - * * Iterates over all top level configuration names. * * @returns {Iterable.} */ - [ Symbol.iterator ]() { - return Object.keys( this._config )[ Symbol.iterator ](); + * names() { + for ( const name of Object.keys( this._config ) ) { + yield name; + } } /** diff --git a/tests/config.js b/tests/config.js index 76ef846..b9c18c6 100644 --- a/tests/config.js +++ b/tests/config.js @@ -460,9 +460,9 @@ describe( 'Config', () => { } ); } ); - describe( 'iterator', () => { - it( 'should return top level keys of the configuration', () => { - expect( Array.from( config ) ).to.be.deep.equal( [ 'creator', 'language', 'resize', 'toolbar', 'options' ] ); + describe( 'names()', () => { + it( 'should return an iterator of top level names of the configuration', () => { + expect( Array.from( config.names() ) ).to.be.deep.equal( [ 'creator', 'language', 'resize', 'toolbar', 'options' ] ); } ); } ); } );