Skip to content
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
22 changes: 15 additions & 7 deletions src/helpers/helpers.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,8 @@ function createSubResolver(parentScopes, resolver, prop, value) {
return false;
}
}
return _createResolver([...set], [''], rootScopes, fallback, () => {
const parent = resolver._getTarget();
if (!(prop in parent)) {
parent[prop] = {};
}
return parent[prop];
});
return _createResolver([...set], [''], rootScopes, fallback,
() => subGetTarget(resolver, prop, value));
}

function addScopesFromKey(set, allScopes, key, fallback) {
Expand All @@ -306,6 +301,19 @@ function addScopesFromKey(set, allScopes, key, fallback) {
return key;
}

function subGetTarget(resolver, prop, value) {
const parent = resolver._getTarget();
if (!(prop in parent)) {
parent[prop] = {};
}
const target = parent[prop];
if (isArray(target) && isObject(value)) {
// For array of objects, the object is used to store updated values
return value;
}
return target;
}

function _resolveWithPrefixes(prop, prefixes, scopes, proxy) {
let value;
for (const prefix of prefixes) {
Expand Down
17 changes: 17 additions & 0 deletions test/specs/helpers.config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,23 @@ describe('Chart.helpers.config', function() {
expect(fn()).toEqual('ok');
});

it('should properly set value to object in array of objects', function() {
const defaults = {};
const options = {
annotations: [{
value: 10
}, {
value: 20
}]
};
const resolver = _attachContext(_createResolver([options, defaults]), {test: true});
expect(resolver.annotations[0].value).toEqual(10);

resolver.annotations[0].value = 15;
expect(options.annotations[0].value).toEqual(15);
expect(options.annotations[1].value).toEqual(20);
});

describe('_indexable and _scriptable', function() {
it('should default to true', function() {
const options = {
Expand Down