Skip to content

Commit

Permalink
Proxy: make sure set value ends up in first scope (#8787)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Apr 2, 2021
1 parent 6789746 commit 515d941
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/helpers/helpers.config.js
Expand Up @@ -275,7 +275,12 @@ function createSubResolver(parentScopes, resolver, prop, value) {
const rootScopes = resolver._rootScopes;
const fallback = resolveFallback(resolver._fallback, prop, value);
const allScopes = [...parentScopes, ...rootScopes];
const set = new Set([value]);
const set = new Set();
if (!(prop in parentScopes[0])) {
// create an empty scope for possible stored values, so we always set the values in top scope.
set.add(parentScopes[0][prop] = {});
}
set.add(value);
let key = addScopesFromKey(set, allScopes, prop, fallback || prop);
if (key === null) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core.controller.tests.js
Expand Up @@ -480,7 +480,7 @@ describe('Chart', function() {
responsive: false
};
chart.update();
expect(chart.options).toEqual(jasmine.objectContaining(options));
expect(chart.options).toEqualOptions(options);
});
});

Expand Down
24 changes: 24 additions & 0 deletions test/specs/helpers.config.tests.js
Expand Up @@ -472,7 +472,31 @@ describe('Chart.helpers.config', function() {
'numbers',
]);
});
});
describe('setting values', function() {
it('should set values to first scope', function() {
const defaults = {
value: true
};
const options = {};
const resolver = _createResolver([options, defaults]);
resolver.value = false;
expect(options.value).toBeFalse();
expect(defaults.value).toBeTrue();
});

it('should set values of sub-objects to first scope', function() {
const defaults = {
sub: {
value: true
}
};
const options = {};
const resolver = _createResolver([options, defaults]);
resolver.sub.value = false;
expect(options.sub.value).toBeFalse();
expect(defaults.sub.value).toBeTrue();
});
});
});

Expand Down

0 comments on commit 515d941

Please sign in to comment.