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

Proxy: make sure set value ends up in first scope #8787

Merged
merged 1 commit into from Apr 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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