Allow single parameter to Defaults.set (#8050)

* Allow single parameter to Defaults.set

* Review update

* Record
This commit is contained in:
Jukka Kurkela 2020-11-19 20:58:24 +02:00 committed by GitHub
parent 6928b23a50
commit f96fa2b96d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -59,14 +59,21 @@ export class Defaults {
this.scales = {};
this.controllers = {};
}
/**
* @param {string} scope
* @param {*} values
* @param {string|object} scope
* @param {object} [values]
*/
set(scope, values) {
return merge(getScope(this, scope), values);
if (typeof scope === 'string') {
return merge(getScope(this, scope), values);
}
return merge(getScope(this, ''), scope);
}
/**
* @param {string} scope
*/
get(scope) {
return getScope(this, scope);
}

View File

@ -333,6 +333,7 @@ export interface DatasetControllerChartComponent extends ChartComponent {
};
}
export type AnyObject = Record<string, unknown>;
export interface Defaults extends CoreChartOptions, ElementChartOptions {
controllers: {
[key in ChartType]: DeepPartial<
@ -352,8 +353,9 @@ export interface Defaults extends CoreChartOptions, ElementChartOptions {
plugins: PluginOptions;
set(scope: string, values: any): any;
get(scope: string): any;
set(values: AnyObject): AnyObject;
set(scope: string, values: AnyObject): AnyObject;
get(scope: string): AnyObject;
/**
* Routes the named defaults to fallback to another scope/name.