Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inflate functions in arrays #5646

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/charts/src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export function inflateFunctions(config) {
if (Array.isArray(config)) {
config.forEach(inflateFunctions);
return;
}
if (
vursen marked this conversation as resolved.
Show resolved Hide resolved
// Check if param is a primitive/null/undefined value
!(config instanceof Object) ||
// Check if param is a plain object (not an array or HC object)
// Check if param is a plain object (not a HC object)
config.constructor !== Object
) {
return;
Expand Down
10 changes: 10 additions & 0 deletions packages/charts/test/private-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe('vaadin-chart private API', () => {
expect(config.tooltip).to.not.have.property('_fn_formatter');
});

it('should inflate function strings in array', () => {
const exportFunction = 'function () {this.exportChart();}';
// eslint-disable-next-line camelcase
const config = { exporting: { buttons: { contextButton: { menuItems: [{ _fn_onclick: exportFunction }] } } } };
inflateFunctions(config);
const exportButton = config.exporting.buttons.contextButton.menuItems[0];
expect(exportButton.onclick.toString()).to.be.equal(exportFunction);
expect(exportButton).to.not.have.property('_fn_onclick');
});

it('should not try to inflate if a non-object value is passed', () => {
// Check for no errors being thrown
inflateFunctions(null);
Expand Down