Skip to content

Commit 07792ca

Browse files
authored
fix: inflate functions in arrays (#5646)
* fix: inflate functions in arrays * refactor: handle arrays in separate blocks for clarification
1 parent a34166f commit 07792ca

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/charts/src/helpers.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
export function inflateFunctions(config) {
2+
if (Array.isArray(config)) {
3+
config.forEach(inflateFunctions);
4+
return;
5+
}
26
if (
37
// Check if param is a primitive/null/undefined value
48
!(config instanceof Object) ||
5-
// Check if param is a plain object (not an array or HC object)
9+
// Check if param is a plain object (not a HC object)
610
config.constructor !== Object
711
) {
812
return;

‎packages/charts/test/private-api.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ describe('vaadin-chart private API', () => {
2929
expect(config.tooltip).to.not.have.property('_fn_formatter');
3030
});
3131

32+
it('should inflate function strings in array', () => {
33+
const exportFunction = 'function () {this.exportChart();}';
34+
// eslint-disable-next-line camelcase
35+
const config = { exporting: { buttons: { contextButton: { menuItems: [{ _fn_onclick: exportFunction }] } } } };
36+
inflateFunctions(config);
37+
const exportButton = config.exporting.buttons.contextButton.menuItems[0];
38+
expect(exportButton.onclick.toString()).to.be.equal(exportFunction);
39+
expect(exportButton).to.not.have.property('_fn_onclick');
40+
});
41+
3242
it('should not try to inflate if a non-object value is passed', () => {
3343
// Check for no errors being thrown
3444
inflateFunctions(null);

0 commit comments

Comments
 (0)