Skip to content

Commit

Permalink
fix(base-plugin): getConfig api should return copy of his config (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ziv authored Sep 26, 2017
1 parent aafc22e commit 26a74ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/plugin/base-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export default class BasePlugin implements IPlugin {
*/
getConfig(attr?: string): any {
if (attr) {
return this.config[attr];
return Utils.Object.copyDeep(this.config[attr]);
}
return this.config;
return Utils.Object.copyDeep(this.config);
}

/**
Expand All @@ -108,7 +108,7 @@ export default class BasePlugin implements IPlugin {
* @returns {void}
*/
updateConfig(update: Object): void {
this.config = Utils.Object.mergeDeep(this.config, update);
Utils.Object.mergeDeep(this.config, update);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/src/plugin/base-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ describe('BasePlugin', () => {
basePlugin.getConfig().should.deep.equal(config);
});

it('should return copy of the plugin config', () => {
basePlugin.getConfig().x = 100;
basePlugin.getConfig().y = 200;
basePlugin.getConfig().x.should.equals(1);
basePlugin.getConfig().y.should.equals(2);
});

it('should return the config attribute value', () => {
basePlugin.getConfig('x').should.deep.equal(1);
});
Expand Down

0 comments on commit 26a74ea

Please sign in to comment.