Skip to content

Commit

Permalink
fix shorthand property default values
Browse files Browse the repository at this point in the history
  • Loading branch information
trash-and-fire committed May 31, 2022
1 parent 565b6e7 commit 6aab7fc
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions packages/lib/src/internal/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export function series<T extends SeriesActionParams>(target: ChartActionResult,
let data = params.reactive ? params.data : null;
let destroyed = false;

// Never use shorthand properties as default values
delete (defaults as any).borderColor;
delete (defaults as any).wickColor;

return {
alive(): boolean {
return !destroyed;
Expand All @@ -84,16 +88,7 @@ export function series<T extends SeriesActionParams>(target: ChartActionResult,
throw new TypeError('Can not change type of series in runtime. Report a bug please');
}

const optionsToApply = merge(clone(defaults), nextOptions);

if (shouldHandleBorderCandlestickOptions(nextOptions)) {
delete optionsToApply.borderColor;
}
if (shouldHandleWickCandlestickOptions(nextOptions)) {
delete optionsToApply.wickColor;
}

subject.applyOptions(optionsToApply);
subject.applyOptions(merge(clone(defaults), nextOptions));

if (!nextReactive) {
data = null;
Expand Down Expand Up @@ -170,17 +165,3 @@ function omit<T extends { reactive?: unknown; data: unknown; type: unknown }>(pa
const {reactive, data, type, ...rest} = params;
return rest;
}

function shouldHandleBorderCandlestickOptions(next: any): boolean {
if (next.borderColor === undefined) {
return next.borderUpColor !== undefined || next.borderDownColor !== undefined;
}
return false;
}

function shouldHandleWickCandlestickOptions(next: any): boolean {
if (next.wickColor === undefined) {
return next.wickUpColor !== undefined || next.wickDownColor !== undefined;
}
return false;
}

0 comments on commit 6aab7fc

Please sign in to comment.