Skip to content

Commit

Permalink
fix(FEC-8637): not possible to pass a function in a plugin configurat…
Browse files Browse the repository at this point in the history
…ion (#163)
  • Loading branch information
Dan Ziv authored Nov 4, 2018
1 parent efbe961 commit cb2c5af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/common/plugins/plugins-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {Utils} from 'playkit-js';
* @returns {boolean} - value is evaluated
*/
const isValueEvaluated = (value: any): boolean =>
(typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean') && !templateRegex.test(value.toString());
(typeof value === 'number' || typeof value === 'function' || typeof value === 'string' || typeof value === 'boolean') &&
!templateRegex.test(value.toString());

/**
* remove unevaluated expressions form object
Expand All @@ -21,7 +22,7 @@ const isValueEvaluated = (value: any): boolean =>
*/
const removeUnevaluatedExpression = (obj = {}): Object =>
Object.entries(obj).reduce((product, [key, value]): Object => {
if (Utils.Object.isObject(value)) {
if (typeof value !== 'function' && Utils.Object.isObject(value)) {
product[key] = removeUnevaluatedExpression(value);
} else if (isValueEvaluated(value)) {
product[key] = value;
Expand Down
17 changes: 17 additions & 0 deletions test/src/common/plugins/plugins-config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {evaluatePluginsConfig} from '../../../../src/common/plugins/plugins-config';

describe('evaluatePluginsConfig', function() {
const config = {
plugins: {
kava: {
myHandler: function() {}
}
}
};

it('should save the function after evaluatePluginsConfig called', function() {
evaluatePluginsConfig(config);
config.plugins.kava.myHandler.should.exist;
config.plugins.kava.myHandler.should.be.instanceof(Function);
});
});

0 comments on commit cb2c5af

Please sign in to comment.